
$(function () {
    $.pageJump();
    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    if (type == 'bind') {
        treeBox_1 = $('.treeBox_1').clone(true);
        $('.treeBox_1').remove();
        $.division('.inp_division_1', '.treeBox_1', '.divisionIcon1');
    } else if (self != top) {
        if (localStorage.user_right || (localStorage.user_name && localStorage.division_code && localStorage.career)) {
            if ($('.data-table').length) frameJs();
            else {
                $.yearAuto(new Date().getFullYear());
                if (type == 'fx' || type == 'bjtj' || type == 'jyzh' || type == 'ghzh') {
                    $.division('.inp_division_1', '.treeBox_1', '.divisionIcon1');
                    var fxActive = $('[id^=road].active, [id^=water].active, [id^=support].active, [id^=province].active,[id^=map].active,[id^=fix].active,[id^=condi].active,[id^=ghzh].active', parent.document),
                        fxActiveId = fxActive.attr('id'),
                        fxtype = fxActive.attr('data-type');
                    var to_division = localStorage.getItem('division_code'),
                        to_career = localStorage.getItem('career'),
                        career = '';
                    if (to_division == '330000' && to_career != '交通运输厅' && to_career != '公路局' && to_career != '港航局' && to_career != '运管局' && to_career != '机场局') career = to_career;
                    if (/^(map)/.test(fxActiveId)) {
                        createMap();
                    } else if (/^fix/.test(fxActiveId) || /^condi/.test(fxActiveId)) {
                        $.post('/api/get_jh_converse?project_type=' + fxActive.attr('data-type') + '&type=' + fxActive.attr('data-show') + '&to_division=' + to_division + '&to_career=' + career + '&status=' + encodeURI('已下达') + '&JHBZND=' + new Date().getFullYear() + '&every_num=' + everyNum + '&now_page=1', {}, function (result) {
                            jhConverse(result);
                            treeBox_1 = $('.treeBox_1').clone(true);
                            $('.treeBox_1').remove();
                        });
                        $('#searchZh').on('click', function () {
                            var JHBZND = $('.JHBZND').val(),
                                XZQH = $('.XZQH').attr('data-vercode') == undefined ? '' : $('.XZQH').attr('data-vercode'),
                                XMMC = $('.XMMC').val() == undefined ? '' : encodeURI($('.XMMC').val()),
                                JHWYBM = $('.JHWYBM').val() == undefined ? '' : $('.JHWYBM').val(),
                                XMLB = $('.XMLB option:selected').val() == undefined ? '' : $('.XMLB option:selected').val(),
                                XMLXDM = $('.XMLXDM option:selected').val() == undefined ? '' : $('.XMLXDM option:selected').val(),
                                JSXZDM = $('.JSXZDM option:selected').val() == undefined ? '' : $('.JSXZDM option:selected').val();
                            if (JHBZND == '' || JHBZND == undefined) JHBZND = new Date().getFullYear();
                            $.yearAuto(JHBZND);
                            $('.inputsTyle').eq(0).val('1');
                            $.post('/api/get_jh_converse?project_type=' + fxActive.attr('data-type') + '&type=' + fxActive.attr('data-show') + '&to_division=' + to_division + '&to_career=' + career + '&status=' + encodeURI('已下达') + '&JHBZND=' + JHBZND + '&XZQH=' + XZQH + '&XMMC=' + XMMC + '&JHWYBM=' + JHWYBM + '&XMLB=' + XMLB + '&XMLXDM=' + XMLXDM + '&JSXZDM=' + JSXZDM + '&every_num=' + everyNum + '&now_page=1', {}, function (result) {
                                jhConverse(result);
                            });
                        });
                        $('#clearZh').on('click', function () {
                            $('.filter').find('input,select').val('');
                            $.yearAuto(new Date().getFullYear());
                            $('.inputsTyle').eq(0).val('1');
                            $.post('/api/get_jh_converse?project_type=' + fxActive.attr('data-type') + '&type=' + fxActive.attr('data-show') + '&to_division=' + to_division + '&to_career=' + career + '&status=' + encodeURI('已下达') + '&JHBZND=' + new Date().getFullYear() + '&every_num=' + everyNum + '&now_page=1', {}, function (result) {
                                jhConverse(result);
                            });
                        })
                    } else if (/^ghzh/.test(fxActiveId)) {
                        $.post('/api/get_gh_converse?project_type=' + fxActive.attr('data-type') + '&status=' + encodeURI('已下达'), {}, function (result) {
                            fiveTotal(result, fxActive.attr('data-type'));
                        })
                    } else {
                        $.post('/api/get_statistics?project_type=' + fxtype + '&show_type=' + fxActive.attr('data-show') + '&JHBZND=' + new Date().getFullYear() + '&status=' + encodeURI('已下达'), {}, function (res) {
                            createTable(res, fxActiveId);
                        });
                        $('#searchZh').on('click', function () {
                            var JHBZND = $('.JHBZND').val();
                            if (JHBZND == '' || JHBZND == undefined) JHBZND = new Date().getFullYear();
                            $.yearAuto(JHBZND);
                            $.post('/api/get_statistics?project_type=' + fxtype + '&show_type=' + fxActive.attr('data-show') + '&JHBZND=' + JHBZND + '&status=' + encodeURI('已下达'), {}, function (res) {
                                createTable(res, fxActiveId);
                            });
                        });
                        $('#clearZh').on('click', function () {
                            $('.filter').find('input,select').val('');
                            $.yearAuto(new Date().getFullYear());
                            $.post('/api/get_statistics?project_type=' + fxtype + '&show_type=' + fxActive.attr('data-show') + '&JHBZND=' + new Date().getFullYear() + '&status=' + encodeURI('已下达'), {}, function (res) {
                                createTable(res, fxActiveId);
                            });
                        });
                    }

                } else if (type == 'sjcx' || type == 'jtcx' || type == 'nctj') {
                    var fxActive = $('[id^=network].active,[id^=station].active,[id^=water].active,[id^=plane].active,[id^=government].active,[id^=province].active,[id^=map].active,[id^=nc].active', parent.document);
                    var fxActiveId = fxActive.attr('id');
                    var project_id = fxActive.attr('data-type'),
                        show_type = fxActive.attr('data-show');
                    $.yearAuto(new Date().getFullYear());
                    if (/^(map)/.test(fxActiveId)) {
                        createMap();
                    } else if (/^nc/.test(fxActiveId)) {
                        $.post('/api/get_nc_converse?type=' + show_type + '&JHBZND=' + new Date().getFullYear() + '&status=' + encodeURI('已下达'), {}, function (result) {
                            ncConverse(result, show_type);
                        });
                        $('#searchZh').on('click', function () {
                            var JHBZND = $('.JHBZND').val();
                            if (JHBZND == '' || JHBZND == undefined) JHBZND = new Date().getFullYear();
                            $.yearAuto(JHBZND);
                            $.post('/api/get_nc_converse?type=' + show_type + '&JHBZND=' + JHBZND + '&status=' + encodeURI('已下达'), {}, function (result) {
                                ncConverse(result, show_type);
                            });
                        });
                        $('#clearZh').on('click', function () {
                            $('.filter').find('input,select').val('');
                            $.yearAuto(new Date().getFullYear());
                            $.post('/api/get_nc_converse?type=' + show_type + '&JHBZND=' + new Date().getFullYear() + '&status=' + encodeURI('已下达'), {}, function (result) {
                                ncConverse(result, show_type);
                            });
                        });
                    } else {
                        $.post('/api/get_sj_converse?project_type=' + project_id + '&type=' + show_type + '&status=' + encodeURI('已下达') + '&JHBZND=' + new Date().getFullYear(), {}, function (result) {
                            sjConverse(result, project_id, show_type);
                        });
                        $('#searchZh').on('click', function () {
                            var JHBZND = $('.JHBZND').val(),
                                XMBM = $('.XMBM').val() == undefined ? '' : $('.XMBM').val(),
                                XMMC = $('.XMMC').val() == undefined ? '' : encodeURI($('.XMMC').val()),
                                KGN = $('.KGN').val() == undefined ? '' : $('.KGN').val(),
                                WGN = $('.WGN').val() == undefined ? '' : $('.WGN').val(),
                                JHXZ = $('.JHXZ option:selected').val() == undefined ? '' : $('.JHXZ option:selected').val(),
                                XZQH = $('.XZQH option:selected').val() == undefined ? '' : $('.XZQH option:selected').val(),
                                JSXZ = $('.JSXZ option:selected').html() == undefined ? '' : $('.JSXZ option:selected').html();
                            if (JHBZND == '' || JHBZND == undefined) JHBZND = new Date().getFullYear();
                            $.yearAuto(JHBZND);
                            $.post('/api/get_sj_converse?project_type=' + project_id + '&type=' + show_type + '&status=' + encodeURI('已下达') + '&JHBZND=' + JHBZND + '&XMBM=' + XMBM + '&XMMC=' + XMMC + '&KGN=' + KGN + '&WGN=' + WGN + '&JHXZ=' + JHXZ + '&XZQH=' + XZQH + '&JSXZ=' + JSXZ, {}, function (result) {
                                sjConverse(result, project_id, show_type);
                            });
                        });
                        $('#clearZh').on('click', function () {
                            $('.filter').find('input,select').val('');
                            $.yearAuto(new Date().getFullYear());
                            $.post('/api/get_sj_converse?project_type=' + project_id + '&type=' + show_type + '&status=' + encodeURI('已下达') + '&JHBZND=' + new Date().getFullYear(), {}, function (result) {
                                sjConverse(result, project_id, show_type);
                            });
                        });
                    };

                }
            }
            $('.selectpicker').selectpicker({
                'selectedText': '新建'
            });
            var thesearch = window.location.search;
            thesearch = thesearch.substring(1, thesearch.length);
            var arr = thesearch.split('&');
            var theshow;
            var theshowreg = /^show/;
            var thetrreg = /^trflag/;
            var themreg = /^mflag/;
            if (!!arr.length) {
                arr.map(function (value, index) {
                    if (theshowreg.test(value)) theshow = value.split('=')[1];
                    if (thetrreg.test(value)) rightFlag = value.split('=')[1] - 0;
                    if (themreg.test(value)) mFlag = value.split('=')[1] - 0;
                })
                if (theshow != undefined) {
                    var theshows = theshow.split(";");
                    theshows.map(function (value) {
                        $("." + value).show();
                    })
                }
                var width = $('table').width();
                var height = $('table').height();
            }
            // 刷新
            $('.refresh').on('click', function () {
                location.reload();
            });
            // 打印
            $('.print').on('click', function () {
                printTable();
            });
            // 导出
            $('.export').on('click', function () {
                exportTable();
            });
        } else {
            if (localStorage.user_name == '' || localStorage.user_name == undefined) {
                alertMs('请登录', 1, function () {
                    window.location.href = '/login.html';
                    window.parent.location.href = '/login.html';
                });
            } else {
                $('.selectpicker').selectpicker({
                    'selectedText': '新建'
                });
                // 刷新
                $('.refresh').on('click', function () {
                    location.reload();
                });
                // 打印
                $('.print').on('click', function () {
                    printTable();
                });
            }
        }
    } else {
        if (localStorage.getItem('btnId') == 'gl') {
            if ($('.selectpicker').length) $('.selectpicker').selectpicker({ 'selectedText': 'all' });
            $.post('/api/get_user_list' + '?every_num=' + everyNum + '&now_page=' + nowPage, {}, function (res) {
                getResult(res, nowPage);
                treeBox_1 = $('.treeBox_1').clone(true);
                $('.treeBox_1').remove();
                $.division('.inp_division_1', '.treeBox_1', '.divisionIcon1');
            });
            //模糊查询
            $('.search-user').on('click', function () {
                $.post('/api/get_user_list?filter=' + ($(this).prev().val() == '是' ? 1 : $(this).prev().val() == '否' ? 0 : $(this).prev().val() + '&every_num=' + everyNum + '&now_page=' + nowPage), {}, function (res) {
                    getResult(res, nowPage);
                });
            });
            //查询
            $('#searchBtn').on('click', function () {
                var dataCode = $('.filter .industry').attr('data-code'),
                    dataCareer = $('.filter .industry').attr('data-career');
                $('.inputsTyle').eq(0).val('1');
                $.post('/api/get_user_list?division=' + dataCode + '&career=' + encodeURI(dataCareer) + '&every_num=' + everyNum + '&now_page=' + nowPage, {}, function (res) {
                    getResult(res, nowPage);
                });
            });
            //清除
            $('#clear').on('click', function () {
                $('.filter .industry').val('').attr('data-code', '').attr('data-career', '');
                $('.inputsTyle').eq(0).val('1');
                $.post('/api/get_user_list' + '?every_num=' + everyNum + '&now_page=' + nowPage, {}, function (res) {
                    getResult(res, nowPage);
                });
            });
            $('.approve').on('click', function () {
                var id = $(this).attr('data-id');
                var trActive = $('#myTable tbody tr.active');
                if ($('#userTable').length) trActive = $('#userTable tbody>tr.active');
                if (!trActive.length && id != 'xz') {
                    alertMs('请点选中一条数据');
                    return false;
                } else if (trActive.hasClass('forbidden') && id != 'xz') {
                    alertMs('你没有操作' + trActive.children().eq(2).html() + '的权限');
                    return false;
                } else {
                    approveModal(id);
                }
                if (id == 'xz') {
                    //新增
                    $('.binds').hide();
                    $('.addBtn').on('click', function () {
                        var newdata = JSON.stringify(newPeople());
                        $.ajax({
                            type: "POST",
                            url: '/api/user_register',
                            data: newdata,
                            success: function (res) {
                                if (!!res) {
                                    alertMs(res["errmsg"]);
                                } else {
                                    $('#myModalgh').modal('hide');
                                    location.reload();
                                }

                            }
                        });
                    })
                } else if (id == 'xg') {
                    //修改
                    $('#jhInfo').html('用户修改');
                    var user_name = trActive.attr('data-id');
                    editPeople(user_name);
                    $('.binds').show();
                    selectPeople(user_name);
                    $('.editBtn').on('click', function () {
                        var editdata = JSON.stringify(newPeople());
                        $.post('/api/user_modify?user_name=' + user_name, editdata, function () {
                            $('#myModalgh').modal('hide');
                            location.reload();
                        });
                    });
                }
            });
            //删除
            $('.user-delete').on('click', function () {
                var index = -1;
                index = $('.data-table tbody>tr.active').index();
                var user_name = $('.data-table tbody>tr.active').attr('data-id');
                if (index == -1) {
                    alertMs('请选择要删除的用户');
                } else {
                    alertMs('确定删除账号:' + user_name, 2, function () {
                        $.post('/api/user_del?user_name=' + user_name, function () {
                            location.reload();
                        })
                    });
                }
            })
        }
        if (localStorage.user_right || (localStorage.user_name && localStorage.division_code && localStorage.career) || location.pathname == '/login.html' || localStorage.getItem('user_name') == 'admin') {
            var the_right = localStorage.user_right;
            $('[id^=road_trial], [id^=road1_trial], [id^=road2_trial],[id^=road3_trial], [id^=road_change_trial], [id^=road1_change_trial], [id^=road2_change_trial], [id^=road3_change_trial]')
                .not('#road_' + the_right + ', #road3_' + the_right + ', #road1_' + the_right + ', #road2_' + the_right + ', #road_change_' + the_right + ', #road1_change_' + the_right + ', #road2_change_' + the_right + ', #road3_change_' + the_right).hide();
            if (the_right == 'trial_third') $('.third_right').show();
            localStorage.acId = $('[id^=road][class=active]').attr('id');
            $('[id^=road]').on('click', function () {
                localStorage.acId = $(this).attr('id');
            });
            $.post('/api/get_notice?user_name=' + localStorage.user_name + '&unread=0', {}, function (res) {
                var count = res['total_num'];
                count ? $('header .icon li.tz span').html(count) : $('header .icon li.tz span').remove();
            });
        } else {
            var pathname = window.location.pathname;
            if (pathname == '/index.html') {
                var search = window.location.search;
                if (search == '') {
                    alertMs('请登录', 1, function () {
                        location.href = '/login.html'
                    });
                } else {
                    var bpUserID = search.substring(10, search.indexOf('bpPassword'));
                    localStorage.setItem('bpUserID', bpUserID);
                    $.post('/api/get_user?bpUserID=' + bpUserID, {}, function (res) {
                        if (res == '') {
                            location.href = '/bind.html';
                        } else {
                            var account = res["user_name"];
                            var password = res["user_pwd"];
                            var url = '/api/user_login?user_name=' + account + '&&user_pwd=' + password;
                            $.ajax({
                                type: 'POST',
                                url: url,
                                success: function (res) {
                                    localStorage.setItem('name', res["name"]);
                                    localStorage.setItem('user_name', res["user_name"]);
                                    localStorage.setItem('user_right', res["trial_first"] - 0 ? "trial_first" : (res["trial_second"] - 0 ? "trial_second" : (res["trial_third"] - 0 ? "trial_third" : (res["trial_forth"] - 0 ? "trial_forth" : ''))));
                                    localStorage.setItem('division_code', res["division_code"]);
                                    localStorage.setItem('career', res["career"]);
                                    localStorage.setItem('modal_right', res['modal_right']);
                                    window.location.href = 'index.html';
                                }
                            });
                        }
                    });
                }
            }
        }
        //解绑
        $('.unbind').on('click', function () {
            alertMs('确认解绑', 2, function () {
                $.post('/api/user_unbind?bpUserID=' + localStorage.getItem('bpUserID'), {}, function () {
                    window.location.href = '/bind.html';
                });
            });
        });
    }
    $(".select li:not(.notselect)").click(function () {
        $('.panel li').removeClass('active')
        $(this).addClass('active')
    })
    $('.tabTitle').on('click', function () {
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(this).attr('data-index');
        var beforeIndex = $('.contain_wn').attr('class').substr(17, 1);
        $('.contain_wn').attr('class', 'contain_wn');
        $('.contain_wn').addClass('active' + index).addClass('active_' + beforeIndex + '_' + index);
    })
    $('.slide').on('click', function () {
        if ($(this).siblings('ul').css('display') == "none") $(this).siblings('ul').slideDown();
        else $(this).siblings('ul').slideUp();
    })
    $('.ext').on('click', function () {
        localStorage.clear();
        sessionStorage.clear();
        window.location.href = '/login.html';
    })
    $('.mianbaoxie').after('<h5 style="float: right">当前账户:' + localStorage.name + '</h5>');
})


function getProject(everyNumber, currentPage, filterObj) {
    var type = '';//表单类型
    var status = ''; //状态值
    var lineSwitch = 0;//是否流水线中
    var userSwtich = 1;//获取当前账号的数据开关
    var thist = localStorage.acId;//访问表单流程位置
    var sub_item = true; //是否为子母项目
    var change = '';   //是否变更
    var jhbg = '';  //计划变更阶段
    var SJSBJG = '';
    var shgl = '';  //是否处于报表审核管理阶段
    var wjstatus = '';  //报表文件状态
    if (thist.indexOf('change') != -1) {
        // 变更阶段
        if (thist.indexOf('fomation') != -1) {
            status = '';
            jhbg = 1;
        } else if (thist.indexOf('Issued') != -1) {
            status = '已下达';
            lineSwitch = 1;
            userSwtich = 1;
            change = 1;
        } else if (thist == 'road_change_trial_forth') {
            lineSwitch = 1;
            userSwtich = 0;
            sub_item = '';
            change = 1;
        } else {
            lineSwitch = 1;
            userSwtich = 0;
            change = 1;
        }
    } else if (thist.indexOf('report') != -1) {
        if (thist != 'road_report_make') {
            var division_code = localStorage.getItem('division_code');
            var titleJg = devisionc[division_code] + '-' + localStorage.getItem('career')
            SJSBJG = division_code == '330000' ? '' : titleJg;
            status = '已确认';
            if (thist == 'road_report_accept' || thist == 'road_report_search') {
                shgl = 1;
                if (division_code == '330000') {
                    SJSBJG = '';
                    shgl = 0;
                } else {
                    SJSBJG = titleJg;
                    shgl = 1;
                }
                if (thist == 'road_report_search') {
                    wjstatus = '审核通过;审核不通过';
                }
            }
        } else {
            status = '';
        }
        sub_item = '';
    } else {
        // 正常阶段
        if (thist.indexOf('fomation') != -1) {
            status = '';
        } else if (thist.indexOf('Issued') != -1) {
            status = '已下达';
            lineSwitch = 1;
            userSwtich = 1;
        } else if (thist == 'road_trial_forth') {
            lineSwitch = 1;
            userSwtich = 0;
            sub_item = '';
        } else if (thist == 'road_combine') {
            sub_item = false;
        } else {
            lineSwitch = 1;
            userSwtich = 0;
        }
    }
    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    var user_name = '';
    if (localStorage.getItem('acId') == 'road_report_upload' || localStorage.getItem('acId') == 'road_report_accept' || localStorage.getItem('acId') == 'road_report_search') {
        user_name = '';
    } else {
        user_name = localStorage.user_name;
    }

    switch (type) {
        case 'xmcg': case 'ghzh':
            type = $('li.active', parent.document).attr('id');
            status = '已下达';
            userSwtich = 1;
            break;
        case 'sy': case 'zc':
            type = $('li.active', parent.document).parent().attr('data-type');
            break;
        default:
            break;
    }

    if (localStorage.getItem('item') != undefined) {
        type = type.replace(/^(sj)/, 'jt');
    }

    var XMLB = $('.XMLB option:selected').val() == undefined ? '' : $('.XMLB option:selected').val(),
        JSLB = $('.JSLB option:selected').val() == undefined ? '' : $('.JSLB option:selected').val(),
        XMLXDM = $('.XMLXDM option:selected').val() == undefined ? '' : $('.XMLXDM option:selected').val(),
        XMBM = $('.XMBM').val() == undefined ? '' : $('.XMBM').val(),
        JHWYBM = $('.JHWYBM').val() == undefined ? '' : $('.JHWYBM').val();

    var parentActive = $('[id^=lnxm_sj].active,[id^=lnxm_jt].active', parent.document);

    var filterObj = $(this).filterSearch();

    var url = '';
    if (type == 'lnxm') {
        if (parentActive.length == 0) {
            url = '/api/get_history_project?project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type') + '&XMLB=' + XMLB + '&JSLB=' + JSLB + '&XMLXDM=' + XMLXDM + '&XMBM=' + XMBM + '&JHWYBM=' + JHWYBM + '&JHNF=' + $('.JHNF').val() + '&JSKGN=' + $('.JSKGN').val() + '&JSWGN=' + $('.JSWGN').val() + '&every_num=' + everyNumber + '&now_page=' + currentPage;
        } else {
            url = '/api/get_project?project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type') + '&every_num=' + everyNumber + '&now_page=' + currentPage;
        }
    } else if (type == 'manage') {
        url = '/api/get_user_list?every_num=' + everyNumber + '&now_page=' + currentPage;
    } else {
        url = '/api/get_project?project_type=' + type + '&status=' + encodeURI(status) + (userSwtich ? ('&user_name=' + user_name) : '') + (lineSwitch ? ('&trial=' + encodeURI(localStorage.division_code + localStorage.career)) : '') + '&sub_item=' + sub_item + '&every_num=' + everyNumber + '&now_page=' + currentPage + '&change=' + change + '&jhbg=' + jhbg + '&SJSBJG=' + SJSBJG + '&shgl=' + shgl + '&wjstatus=' + encodeURI(wjstatus);
    }

    $.post(url, JSON.stringify(filterObj), function (res) {
        getResult(res, currentPage);
    });

}


var pline = null;
var kzdPlineArr = [];
var bookmarkFun = null;
var timer = null;
var treeBox_1 = null,
    treeBox_3 = null,
    treeBox_4 = null;
var apiType = 1;
var maplet = null;
var rightFlag = 1;
var mFlag = 0;
var data = [];
var fiveData = [],
    jtData = [],
    xmfmData = [],
    jtAuto = [];
var addItemArr = [],
    selectItemArr = [];
var devisionc = {
    '330000': '浙江省',
    '330100': '浙江省-杭州市',
    '330102': '浙江省-杭州市-上城区',
    '330103': '浙江省-杭州市-下城区',
    '330104': '浙江省-杭州市-江干区',
    '330105': '浙江省-杭州市-拱墅区',
    '330106': '浙江省-杭州市-西湖区',
    '330108': '浙江省-杭州市-滨江区',
    '330109': '浙江省-杭州市-萧山区',
    '330110': '浙江省-杭州市-余杭区',
    '330122': '浙江省-杭州市-桐庐县',
    '330127': '浙江省-杭州市-淳安县',
    '330182': '浙江省-杭州市-建德市',
    '330183': '浙江省-杭州市-富阳市',
    '330185': '浙江省-杭州市-临安市',
    '330200': '浙江省-宁波市',
    '330203': '浙江省-宁波市-海曙区',
    '330204': '浙江省-宁波市-江东区',
    '330205': '浙江省-宁波市-江北区',
    '330206': '浙江省-宁波市-北仑区',
    '330211': '浙江省-宁波市-镇海区',
    '330212': '浙江省-宁波市-鄞州区',
    '330225': '浙江省-宁波市-象山县',
    '330226': '浙江省-宁波市-宁海县',
    '330281': '浙江省-宁波市-余姚市',
    '330282': '浙江省-宁波市-慈溪市',
    '330283': '浙江省-宁波市-奉化市',
    '330300': '浙江省-温州市',
    '330302': '浙江省-温州市-鹿城区',
    '330303': '浙江省-温州市-龙湾区',
    '330304': '浙江省-温州市-瓯海区',
    '330322': '浙江省-温州市-洞头县',
    '330324': '浙江省-温州市-永嘉县',
    '330326': '浙江省-温州市-平阳县',
    '330327': '浙江省-温州市-苍南县',
    '330328': '浙江省-温州市-文成县',
    '330329': '浙江省-温州市-泰顺县',
    '330381': '浙江省-温州市-瑞安市',
    '330382': '浙江省-温州市-乐清市',
    '330400': '浙江省-嘉兴市',
    '330402': '浙江省-嘉兴市-南湖区',
    '330411': '浙江省-嘉兴市-秀洲区',
    '330421': '浙江省-嘉兴市-嘉善县',
    '330424': '浙江省-嘉兴市-海盐县',
    '330481': '浙江省-嘉兴市-海宁市',
    '330482': '浙江省-嘉兴市-平湖市',
    '330483': '浙江省-嘉兴市-桐乡市',
    '330500': '浙江省-湖州市',
    '330502': '浙江省-湖州市-吴兴区',
    '330503': '浙江省-湖州市-南浔区',
    '330521': '浙江省-湖州市-德清县',
    '330522': '浙江省-湖州市-长兴县',
    '330523': '浙江省-湖州市-安吉县',
    '330600': '浙江省-绍兴市',
    '330602': '浙江省-绍兴市-越城区',
    '330621': '浙江省-绍兴市-绍兴县',
    '330624': '浙江省-绍兴市-新昌县',
    '330681': '浙江省-绍兴市-诸暨市',
    '330682': '浙江省-绍兴市-上虞市',
    '330683': '浙江省-绍兴市-嵊州市',
    '330700': '浙江省-金华市',
    '330702': '浙江省-金华市-婺城区',
    '330703': '浙江省-金华市-金东区',
    '330723': '浙江省-金华市-武义县',
    '330726': '浙江省-金华市-浦江县',
    '330727': '浙江省-金华市-磐安县',
    '330781': '浙江省-金华市-兰溪市',
    '330782': '浙江省-金华市-义乌市',
    '330783': '浙江省-金华市-东阳市',
    '330784': '浙江省-金华市-永康市',
    '330800': '浙江省-衢州市',
    '330802': '浙江省-衢州市-柯城区',
    '330803': '浙江省-衢州市-衢江区',
    '330822': '浙江省-衢州市-常山县',
    '330824': '浙江省-衢州市-开化县',
    '330825': '浙江省-衢州市-龙游县',
    '330881': '浙江省-衢州市-江山市',
    '330900': '浙江省-舟山市',
    '330902': '浙江省-舟山市-定海区',
    '330903': '浙江省-舟山市-普陀区',
    '330921': '浙江省-舟山市-岱山县',
    '330922': '浙江省-舟山市-嵊泗县',
    '331000': '浙江省-台州市',
    '331002': '浙江省-台州市-椒江区',
    '331003': '浙江省-台州市-黄岩区',
    '331004': '浙江省-台州市-路桥区',
    '331021': '浙江省-台州市-玉环县',
    '331022': '浙江省-台州市-三门县',
    '331023': '浙江省-台州市-天台县',
    '331024': '浙江省-台州市-仙居县',
    '331081': '浙江省-台州市-温岭市',
    '331082': '浙江省-台州市-临海市',
    '331100': '浙江省-丽水市',
    '331102': '浙江省-丽水市-莲都区',
    '331121': '浙江省-丽水市-青田县',
    '331122': '浙江省-丽水市-缙云县',
    '331123': '浙江省-丽水市-遂昌县',
    '331124': '浙江省-丽水市-松阳县',
    '331125': '浙江省-丽水市-云和县',
    '331126': '浙江省-丽水市-庆元县',
    '331127': '浙江省-丽水市-景宁畲族自治县',
    '331181': '浙江省-丽水市-龙泉市'
}

var everyNum = 10,   //每页条数
    totalNum = '',   //总条数
    nowPage = 1;  //当前页码

/* js running in the frame */
function frameJs() {
    if (localStorage.division_code != '330000' && localStorage.career != '交通运输厅') {
        $('.importForm').hide();
        $('.import').on('click', function () {
            alertMs('你没有权限进行导入操作');
        })
    }

    treeBox_1 = $('.treeBox_1').clone(true);
    treeBox_3 = $('.treeBox_3').clone(true);
    treeBox_4 = $('.treeBox_4').clone(true);
    $('.treeBox_1').remove();
    $('.treeBox_3').remove();
    $('.treeBox_4').remove();
    // var mapArray = data.map_local;
    // mapPolyline();
    if ($('#myMap').length > 0) {
        // + function initMap(){
        maplet = new Maplet("myMap");
        maplet.centerAndZoom(new MPoint(120.18323, 30.21436), 11);
        maplet.addControl(new MStandardControl());
        // }
    }
    getProject(everyNum, nowPage);

    $('#searchBtn').off('click').on('click', function () {
        var filterObj = $(this).filterSearch();
        $('.inputsTyle').eq(0).val('1');
        getProject(everyNum, 1);
    });
    $('#clear').off('click').on('click', function () {
        $('.inputsTyle').eq(0).val('1');
        $(this).clear(10);
    });

    // 历年项目查询
    $('#searchHis').on('click', function () {
        var XMLB = $('.XMLB option:selected').val() == undefined ? '' : $('.XMLB option:selected').val(),
            JSLB = $('.JSLB option:selected').val() == undefined ? '' : $('.JSLB option:selected').val(),
            XMLXDM = $('.XMLXDM option:selected').val() == undefined ? '' : $('.XMLXDM option:selected').val(),
            XMBM = $('.XMBM').val() == undefined ? '' : $('.XMBM').val(),
            JHWYBM = $('.JHWYBM').val() == undefined ? '' : $('.JHWYBM').val();
        $('.inputsTyle').eq(0).val('1');
        $.post('/api/get_history_project?project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type') + '&XMLB=' + XMLB + '&JSLB=' + JSLB + '&XMLXDM=' + XMLXDM + '&XMBM=' + XMBM + '&JHWYBM=' + JHWYBM + '&JHNF=' + $('.JHNF').val() + '&JSKGN=' + $('.JSKGN').val() + '&JSWGN=' + $('.JSWGN').val() + '&every_num=' + everyNum + '&now_page=' + nowPage, {}, function (res) {
            getResult(res, nowPage);
        })
    });
    // 历年项目清除
    $('#clearHis').on('click', function () {
        $('.inputsTyle').eq(0).val('1');
        $.post('/api/get_history_project?project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type') + '&every_num=' + everyNum + '&now_page=' + nowPage, {}, function (res) {
            getResult(res, nowPage);
        });
        $('.filter').find('input,select').val('');
    });
    // 历年项目删除
    $('.del-history').on('click', function () {
        delData();
    });
    //财务确认
    $('.confirm').on('click', function () {
        $(this).hasClass('one') ? upload('财务确认', 'one') : upload('财务确认', 'three');
    })
    $('.upload').on('click', function () {
        upload('上报');
    });
    $('.cancelupload').on('click', function () {
        cancelUpload();
    });
    $('.importForm input').on('change', function () {
        var fileData = new FormData($('.importForm')[0]),
            importType = $(this).attr('data-type');
        if (localStorage.division_code == '330000' && localStorage.career == "交通运输厅") {
            var url = type == 'lnxm' ? ('/api/import_history?project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type')) : ('/api/import?project_type=' + type + '&user_name=' + localStorage.getItem('user_name'));
            $.ajax({
                type: "post",
                url: url,
                data: fileData,
                processData: false,
                contentType: false,
                beforeSend: function () {
                    $('#barTop', parent.document).css({
                        "width": '50%'
                    });
                },
                success: function (result) {
                    $('#barTop', parent.document).css({
                        "width": '100%'
                    });
                    setTimeout(function () {
                        $('#barTop', parent.document).css({
                            "opacity": '0'
                        });
                    }, 700);
                    setTimeout(function () {
                        $('#barTop', parent.document).css({
                            "width": '0'
                        });
                        if (type == 'lnxm') {
                            alertMs('导入成功', 1, function () {
                                location.reload();
                            });
                        } else {
                            alertMs('导入成功，已下达', 1, function () {
                                var dataLog = [getDate(0), localStorage.name, '下达了' + result[0]['XMMC']];
                                dataLog = JSON.stringify(dataLog);
                                $.post('/api/set_log?project_id=' + result[0]['identifier'], dataLog, function () {
                                    location.reload();
                                })
                            });
                        }
                    }, 1000);
                },
                error: function (error) {
                    console.log(error.responseText);
                }
            });
        }
    });

    $('.approve').on('click', function () {
        var id = $(this).attr('data-id');
        var trActive = '',
            projectId = '',
            txt = '';
        var Active = $('#myTable tbody tr>td:first-child input[type="checkbox"]:checked');
        if (id != 'xz') {
            switch (Active.length) {
                case 0:
                    alertMs('请勾选一条数据');
                    return false;
                    break;
                case 1:
                    trActive = Active.parents('tr');
                    projectId = trActive.attr('data-id');
                    txt = trActive.find('td').eq(2).html();
                    if (trActive.hasClass('forbidden') && localStorage.getItem('acId') != 'road_combine') {
                        alertMs('你没有操作' + trActive.children().eq(2).html() + '的权限');
                        return false;
                    } else {
                        approveModal(id, projectId, txt);
                    }
                    break;
                default:
                    alertMs('只能勾选一条数据进行操作');
                    return false;
                    break;
            }
        } else {
            approveModal(id, projectId, txt);
        }
    });

    $('.search').on('click', function () {
        $(this).search()
    });
    $('.delete_btn').on('click', function () {
        delData();
    });

    //刷新
    $('.refresh').on('click', function () {
        location.reload();
    })

    //初审
    $('.confirmBtn').eq(2).off('click').on('click', function () {
        var Project_id = '',
            theindex = '';
        $('.data-table tbody>tr').each(function (i) {
            if ($(this).find('td:first-child input[type="checkbox"]').is(':checked')) {
                Project_id = $(this).attr('data-id');
                theindex = i;
            }
        })
        var data_trail = trial('cs', Project_id, '初审');
        var result = data_trail.result;
        var status = '';
        var from_trial = data[theindex].up_org;
        var from_division = from_trial.substr(0, 6);
        var from_career = from_trial.replace(/\d{6}/, '');
        var division = '',
            career = '';
        switch (result) {
            case '初审不通过':
                status = '初审不通过';
                division = from_division;
                career = from_career;
                break;
            case '初审退回':
                status = '初审退回';
                division = from_division;
                career = from_career;
                break;
            default:
                status = '审查未接收';
                division = $('#ghcsModal .second_trial option:selected').val();
                career = $('#ghcsModal .second_trial option:selected').attr('data-vername');
                break;
        }
        if (result == '') {
            $('#ghcsModal .result').addClass('checkErr');
            return false;
        } else {
            var data_trail = JSON.stringify(data_trail);
            var url = '/api/trial_first?project_id=' + Project_id + '&status=' + encodeURI(status) + '&to_division=' + division + '&to_career=' + encodeURI(career) + '&user_name=' + localStorage.user_name;
            $.post(url, data_trail, function (res) {
                $('#myModalgh').modal('hide')
                var dataLog = [getDate(0), localStorage.name, result];
                dataLog = JSON.stringify(dataLog);
                $.post('/api/set_log?project_id=' + Project_id, dataLog, function () {
                    location.reload()
                })
            });
        }
    });

    //审查
    $('.confirmBtn').eq(3).off('click').on('click', function () {
        var Project_id = '',
            theindex = '';
        $('.data-table tbody>tr').each(function (i) {
            if ($(this).find('td:first-child input[type="checkbox"]').is(':checked')) {
                Project_id = $(this).attr('data-id');
                theindex = i;
            }
        })
        var data_trail = trial('sc', Project_id, '审查');
        var result = data_trail.result;
        var status = '';
        var from_trial1 = data[theindex].up_org,
            from_division1 = from_trial1.substr(0, 6),
            from_career1 = from_trial1.replace(/\d{6}/, '');
        var from_trial2 = $('#ghscModal .first_trial').val() != '' ? $('#ghscModal .first_trial').attr('data-vercode') + $('#ghscModal .first_trial').attr('data-vername') : data[theindex].up_org,
            from_division2 = from_trial2.substr(0, 6),
            from_career2 = from_trial2.replace(/\d{6}/, '');
        var division = '',
            career = '';
        switch (result) {
            case '审查不通过':
                status = '审查不通过';
                division = from_division1;
                career = from_career1;
                break;
            case '审查退回':
                status = '审查退回';
                division = from_division2;
                career = from_career2;
                break;
            default:
                status = '审核未接收';
                division = '330000';
                career = '交通运输厅';
                break;
        }
        if (result == '') {
            $('#ghscModal .result').addClass('checkErr');
            return false;
        } else {
            var data_trail = JSON.stringify(data_trail);
            var url = '/api/trial_second?project_id=' + Project_id + '&&status=' + encodeURI(status) + '&&to_division=' + division + '&&to_career=' + encodeURI(career) + '&user_name=' + localStorage.user_name;
            $.post(url, data_trail, function (res) {
                $('#myModalgh').modal('hide')
                var dataLog = [getDate(0), localStorage.name, result];
                dataLog = JSON.stringify(dataLog);
                $.post('/api/set_log?project_id=' + Project_id, dataLog, function () {
                    location.reload();
                })
            })
        }
    });

    //审核
    $('.confirmBtn').eq(4).off('click').on('click', function () {
        var Project_id = '',
            theindex = '';
        $('.data-table tbody>tr').each(function (i) {
            if ($(this).find('td:first-child input[type="checkbox"]').is(':checked')) {
                Project_id = $(this).attr('data-id');
                theindex = i;
            }
        });
        var data_trail = trial('sh', Project_id, '审核');
        var result = data_trail.result;
        var status = '';
        var from_trial1 = data[theindex].up_org,
            from_division1 = from_trial1.substr(0, 6),
            from_career1 = from_trial1.replace(/\d{6}/, '');  //上报机构
        var from_division2 = '',
            from_career2 = '';
        var first = $('#ghshModal .first_trial').attr('data-vercode') + $('#ghshModal .first_trial').attr('data-vername'),
            second = $('#ghshModal .second_trial option:selected').val() + $('#ghshModal .second_trial option:selected').attr('data-vername');
        if (second != '') {
            from_division2 = second.substr(0, 6);
            from_career2 = second.replace(/\d{6}/, '');
        } else if (first != '') {
            from_division2 = first.substr(0, 6);
            from_career2 = first.replace(/\d{6}/, '');
        } else {
            from_division2 = from_division1;
            from_career2 = from_career1;
        }
        var to_division = '';
        var to_career = '';
        var division = '',
            career = '';
        switch (result) {
            case '审核不通过':
                status = '审核不通过';
                division = from_division1;
                career = from_career1;
                break;
            case '审核退回':
                status = '审核退回';
                division = from_division2;
                career = from_career2;
                break;
            default:
                if ($('.data-table').hasClass('sj-table') || $('.data-table').hasClass('wn-table')) {
                    status = '已下达';
                    division = from_division1;
                    career = from_career1;
                } else {
                    status = '审核通过审批未接收';
                    division = '330000';
                    career = '交通运输厅';
                }
                break;
        }
        if (result == '') {
            $('#ghshModal .result').addClass('checkErr');
            return false;
        } else {
            var data_trail = JSON.stringify(data_trail);
            var url = '/api/trial_third?project_id=' + Project_id + '&&status=' + encodeURI(status) + '&&to_division=' + division + '&&to_career=' + encodeURI(career) + '&user_name=' + localStorage.user_name;
            $.post(url, data_trail, function (res) {
                $('#myModalgh').modal('hide')
                var dataLog = [getDate(0), localStorage.name, result];
                dataLog = JSON.stringify(dataLog);
                $.post('/api/set_log?project_id=' + Project_id, dataLog, function () {
                    location.reload();
                })
            })
        }
    });

    // 审批
    $('.confirmBtn').eq(5).off('click').on('click', function () {
        var Project_id = '',
            theindex = '';
        $('.data-table tbody>tr').each(function (i) {
            if ($(this).find('td:first-child input[type="checkbox"]').is(':checked')) {
                Project_id = $(this).attr('data-id');
                theindex = i;
            }
        })
        var data_trail = trial('sp', Project_id, '审批');
        var result = data_trail.result;
        var status = '';
        var from_trial1 = data[theindex].up_org;
        var from_division1 = from_trial1.substr(0, 6);
        var from_career1 = from_trial1.replace(/\d{6}/, '');
        var from_division2 = $('#ghcsModal .second_trial option:selected').val();
        var from_career2 = $('#ghcsModal .second_trial option:selected').attr('data-vername');
        var division = '',
            career = '';
        switch (result) {
            case '审批不通过':
                status = '审批不通过';
                division = from_division1;
                career = from_career1;
                break;
            case '审批退回':
                status = '审批退回';
                division = '330000';
                career = '交通运输厅';
                break;
            default:
                status = '已下达';
                division = from_division1;
                career = from_career1;
                break;
        }
        if (result == '') {
            $('#ghspModal .result').addClass('checkErr');
            return false;
        } else {
            var data_trail = JSON.stringify(data_trail);
            var url = '/api/trial_forth?project_id=' + Project_id + '&status=' + encodeURI(status) + '&to_division=' + division + '&to_career=' + encodeURI(career) + '&user_name=' + localStorage.user_name;
            $.post(url, data_trail, function (res) {
                $('#myModalgh').modal('hide')
                var dataLog = [getDate(0), localStorage.name, result];
                dataLog = JSON.stringify(dataLog);
                $.post('/api/set_log?project_id=' + Project_id, dataLog, function () {
                    location.reload();
                })
            })
        }
    });

    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];

    if ((/^(nc)/.test(type) && type != 'nctj' && type != 'nclw') || (/^(sj)/.test(type) && type != 'sjcx' && type != 'sjbb') || type == 'gljy' || type == 'syjy' || type == 'zcxt' || (/^(jt)/.test(type) && type != 'jtcx') || type == 'tl') {
        $.getAlready(type);
        if (type == 'gljy' || type == 'syjy' || type == 'zcxt') $.getJtAlready(type);
    }
}

(function ($) {
    $.fn.search = function () {
        var selectTd = {};
        var method = {
            searchRange: function () {
                if ($('.data-table thead tr').length == 1) {
                    $('.data-table thead tr').eq(0).children().map(function (number) {
                        if (number > 0) {
                            selectTd[$(this).html()] = number;
                        }
                    });
                } else if ($('.data-table thead tr').length == 2) {
                    var delayNumber = 0;
                    $('.data-table thead tr').eq(0).children().map(function (number) {
                        if (number > 0) {
                            var name = '';
                            var name1 = $(this).html();
                            if ($(this).attr('colspan') == undefined) {
                                name += name1
                                selectTd[name] = number;
                            } else {
                                delayNumber += $(this).attr('colspan') - 0;
                                $('.data-table thead tr').eq(1).children().map(function () {
                                    var name2 = $(this).html();
                                    name = name1 + '|' + name2;
                                    selectTd[name] = number + delayNumber;
                                })
                            }
                        }
                    });
                } else if ($('.data-table thead tr').length == 3) {
                    var delayNumber = 0;
                    $('.data-table thead tr').eq(0).children().map(function (number) {
                        if (number > 0) {
                            var name = '';
                            var name1 = $(this).html();
                            if ($(this).attr('colspan') == undefined) {
                                name += name1
                                selectTd[name] = number;
                            } else {
                                delayNumber += $(this).attr('colspan') - 0;
                                $('.data-table thead tr').eq(1).children().map(function () {
                                    var name2 = $(this).html();
                                    if ($(this).attr('colspan') == undefined) {
                                        name = name1 + '|' + name2;
                                        selectTd[name] = number;
                                    } else {
                                        delayNumber += $(this).attr('colspan') - 0;
                                        $('.data-table thead tr').eq(2).children().map(function () {
                                            var name3 = $(this).html();
                                            name = name1 + '|' + name2 + '|' + name3;
                                            selectTd[name] = number + delayNumber;
                                        })
                                    }
                                })
                            }
                        }
                    });
                } else if ($('.data-table thead tr').length == 4) {
                    var delayNumber = 0;
                    $('.data-table thead tr').eq(0).children().map(function (number) {
                        if (number > 0) {
                            var name = '';
                            var name1 = $(this).html();
                            if ($(this).attr('colspan') == undefined) {
                                name += name1
                                selectTd[name] = number;
                            } else {
                                delayNumber += $(this).attr('colspan') - 0;
                                $('.data-table thead tr').eq(1).children().map(function () {
                                    var name2 = $(this).html();
                                    if ($(this).attr('colspan') == undefined) {
                                        name = name1 + '|' + name2;
                                        selectTd[name] = number;
                                    } else {
                                        delayNumber += $(this).attr('colspan') - 0;
                                        $('.data-table thead tr').eq(2).children().map(function () {
                                            var name3 = $(this).html();
                                            if ($(this).attr('colspan') == undefined) {
                                                name = name1 + '|' + name2 + '|' + name3;
                                                selectTd[name] = number + delayNumber;
                                            } else {
                                                delayNumber += $(this).attr('colspan') - 0;
                                                $('.data-table thead tr').eq(3).children().map(function () {
                                                    var name4 = $(this).html();
                                                    name = name1 + '|' + name2 + '|' + name3 + '|' + name4;
                                                    selectTd[name] = number + delayNumber;
                                                })
                                            }
                                        })
                                    }
                                })
                            }
                        }
                    });
                } else if ($('.data-table thead tr').length == 5) {
                    var delayNumber = 0;
                    $('.data-table thead tr').eq(0).children().map(function (number) {
                        if (number > 0) {
                            var name = '';
                            var name1 = $(this).html();
                            if ($(this).attr('colspan') == undefined) {
                                name += name1
                                selectTd[name] = number;
                            } else {
                                delayNumber += $(this).attr('colspan') - 0;
                                $('.data-table thead tr').eq(1).children().map(function () {
                                    var name2 = $(this).html();
                                    if ($(this).attr('colspan') == undefined) {
                                        name = name1 + '|' + name2;
                                        selectTd[name] = number;
                                    } else {
                                        delayNumber += $(this).attr('colspan') - 0;
                                        $('.data-table thead tr').eq(2).children().map(function () {
                                            var name3 = $(this).html();
                                            if ($(this).attr('colspan') == undefined) {
                                                name = name1 + '|' + name2 + '|' + name3;
                                                selectTd[name] = number + delayNumber;
                                            } else {
                                                delayNumber += $(this).attr('colspan') - 0;
                                                $('.data-table thead tr').eq(3).children().map(function () {
                                                    var name4 = $(this).html();
                                                    if ($(this).attr('colspan') == undefined) {
                                                        name = name1 + '|' + name2 + '|' + name3 + '|' + name4;
                                                        selectTd[name] = number + delayNumber;
                                                    } else {
                                                        delayNumber += $(this).attr('colspan') - 0;
                                                        $('.data-table thead tr').eq(4).children().map(function () {
                                                            var name5 = $(this).html();
                                                            name = name1 + '|' + name2 + '|' + name3 + '|' + name4 + '|' + name5;
                                                            selectTd[name] = number + delayNumber;
                                                        })
                                                    }
                                                })
                                            }
                                        })
                                    }
                                })
                            }
                        }
                    });
                }
                var option = '';
                for (var key in selectTd) {
                    option += '<option>' + key + '</option>'
                }
                return option;
            },
            createSearchTxt: function () {
                var searchDiv = '';
                if (window.localStorage) {
                    if (localStorage["searchTxt"] != '' && localStorage["searchTxt"] != undefined) {
                        var txtArr = localStorage["searchTxt"].split(";");
                        var searchSpan = '';
                        $.map(txtArr, function (T) {
                            searchSpan += '<h5 style="margin: 0; padding: 10px 0;">' + T + '</h5>';
                        })
                        searchDiv = '<div class="searchDiv">' +
                            searchSpan +
                            '</div>';
                    } else {
                        localStorage["searchTxt"] = '';
                        searchDiv = '<div class="searchDiv">' +
                            '</div>';
                    }
                }
                return searchDiv;
            },
            search: function () {
                var reg = $('.matchTxtInput').val(); //查找内容
                var regRuleCase = $('#checkForCase').is(':checked'); //区分大小写
                var regRuleRange = $('.matchRangeSelect').find('option:selected').html(); //查找字段
                var regRuleWay = $('.matchWaySelect').find('option:selected').index(); //查找方式
                var regRuleDir = $('.matchDir').find('option:selected').index(); //查找方向
                var sum = $('.data-table tbody tr').not('.none').length;
                var current = $('.data-table tbody tr.active').index() || 0;
                //判断向上翻页还是向下翻页  
                var judge = function (type) {
                    switch (type) {
                        case 0:
                            if ($('.data-table tbody tr').index($('.active')) == $('.data-table tbody tr').length - 1 && $('.inputsTyle').val() - 0 < $('.inputsTyle.pageTotally').val() - 0) {
                                $.iconDownChange(1, 9);
                                current = -1;
                                sum = $('.data-table tbody tr').length;
                            }
                            break;
                        case 1:
                            if ($('.data-table tbody tr').index($('.active')) == 0 && $('.inputsTyle').val() - 0 > 1) {
                                $.iconUpChange(-1, 9);
                            }
                            current = $('.data-table tbody tr.active').index() == -1 ? $('.data-table tbody tr').length : $('.data-table tbody tr.active').index();
                            break;
                        default:
                            break;
                    }
                }
                switch (regRuleWay) {
                    case 0:
                        if (!regRuleCase) {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().toLowerCase() === reg.toLowerCase()) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().toLowerCase() === reg.toLowerCase()) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                };
                            }
                        } else {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html() === reg) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html() === reg) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                }
                            }
                        }
                        break;
                    case 1:
                        if (!regRuleCase) {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().toLowerCase().indexOf(reg.toLowerCase()) != -1) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().toLowerCase().indexOf(reg.toLowerCase()) != -1) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                };
                            }
                        } else {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg) != -1) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg) != -1) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                }
                            }
                        }
                        break;
                    case 2:
                        if (!regRuleCase) {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg.toLowerCase()) == 0) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg.toLowerCase()) == 0) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                };
                            }
                        } else {
                            if (regRuleDir) {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j < $('.inputsTyle').eq(1).val() - 0; j++) {
                                    judge(0);
                                    for (var i = current + 1; i < sum; i++) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg) == 0) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != $('.inputsTyle').eq(1).val() - 0 ? $.iconDownChange(1, 9) : '';
                                };
                            } else {
                                for (var j = $('.inputsTyle').eq(0).val() - 1; j >= 0; j--) {
                                    judge(1)
                                    for (var i = current - 1; i >= 0; i--) {
                                        if ($('.data-table tbody tr').eq(i).children().eq(selectTd[regRuleRange]).html().indexOf(reg) == 0) {
                                            $('.data-table tbody tr').eq(i).addClass('active').siblings().removeClass('active');
                                            $('.inputsTyle').eq(3).val($('.data-table tbody tr.active').index() + ($('.inputsTyle').eq(0).val() - 1) * ($('.inputsTyle').eq(2).val() - 0) + 1)
                                            return false;
                                        }
                                    }
                                    $('.inputsTyle').eq(0).val() - 0 != 0 ? $.iconUpChange(-1, 9) : '';
                                }
                            }
                        }
                        break;
                }
                alertMs('未找到该项目')
            }
        }
        var searchTxt = '<div class="searchOut" style="position:fixed;left: 50%; top: 50%; z-index:999;width: 590px;height: 250px; transform: translate(-50%,-50%);background-color: #f9f9f9;box-shadow: 0 0 10px #333">' +
            '<i class="closeSearch" style="float:right;color: #fff;cursor: pointer;line-height:40px;margin-right:10px;">×</i>' +
            '<h4 class="searchtitle" style="color: #fff;background-color: #850b06;margin: 0;padding: 0;text-indent: 1em;line-height:40px;" >查找文本</h4>' +
            '<div class="searchInner" style="padding: 15px 10px;">' +
            '<div style="height: 40px; position: relative;"><span class="matchTxt">查找内容：</span><input class="matchTxtInput" type="text" style="min-width: 300px; min-height: 30px;"/></div>' +
            '<div style="height: 40px;"><span class="matchRange">查找范围：</span><select class="matchRangeSelect" style="min-width: 150px; min-height: 30px;width: 350px;">' + method.searchRange() + '</select></div>' +
            '<div style="height: 40px;"><span class="matchWay">匹配方式：</span><select class="matchWaySelect" style="min-width: 150px; min-height: 30px;">' +
            '<option>全部匹配</option>' +
            '<option>局部匹配</option>' +
            '<option>起始匹配</option>' +
            '</select></div>' +
            '<div style="height: 40px;"><span>搜索方向：</span><select class="matchDir" style="min-width: 150px; min-height: 30px; margin-right: 45px;">' +
            '<option>向上</option>' +
            '<option>向下</option>' +
            '</select>' +
            '<button class="searchB" style="border: none;padding: 10px 30px;background-color: #850b06; color: #fff; margin-right: 10px;">查找</button>' +
            '<button class="cancle" style="border: none;padding: 10px 30px;background-color: #850b06; color: #fff; margin-right: 10px;">取消</button>' +
            '</div>' +
            '<input id="checkForCase" type="checkbox"  style="margin-left: 75px;"/><label for="checkForCase" style="font-weight: 300;">区分大小写</label>' +
            '</div>' +
            '</div>';
        var search = $(searchTxt);
        $('body').append(search);
        $('.closeSearch , .cancle').click(function () {
            search.remove();
        })
        $('.matchTxtInput').click(function (e) {
            e.stopPropagation();
        })
        $('.matchTxtInput').on('focus', function (e) {
            e.stopPropagation();
            $(this).after(method.createSearchTxt());
            $('.searchDiv h5').click(function (e) {
                e.stopPropagation();
                $('.matchTxtInput').val($(this).html());
            })
            $('body').on('click', function (e) {
                $('.searchDiv').remove();
                $('.matchTxtInput').blur();
            })
            $('.searchDiv').css({
                'position': 'absolute',
                'left': $('.matchTxt').outerWidth() + 'px',
                'top': $('.matchTxtInput').outerHeight() + 'px',
                'z-index': '1',
                'width': $('.matchTxtInput').width() + 'px',
                'min-height': '50px',
                'max-height': '100px',
                'background-color': '#fff',
                'border': '1px solid #333',
                'overflow-y': 'scroll',
                'overflow-x': 'hidden'
            })
        })
        $('.searchB').on('click', function () {
            method.search();
            var str = localStorage.searchTxt || '';
            var arr = str.split(';');
            var flag = 0;
            $.each(arr, function (t, value) {
                if (value == $('.matchTxtInput').val()) flag = 1;
            })
            if (!flag) localStorage.searchTxt += $('.matchTxtInput').val() + ';';

        })
        $('body').on('mousedown', function (e) {
            if (e.target.className == 'searchtitle') {
                var mX = e.screenX,
                    mY = e.screenY;
                var divX = parseFloat($('.searchOut').css('left')),
                    divY = parseFloat($('.searchOut').css('top'));
                var dX = mX - divX,
                    dY = mY - divY;
                $(this).css('cursor', 'move')
                $('body').on('mousemove', function (ev) {
                    $('.searchOut').css({
                        'left': ev.screenX - dX + 'px',
                        'top': ev.screenY - dY + 'px'
                    })
                })
            }
        })
        $('body').on('mouseup', function (e) {
            $(this).css('cursor', 'auto')
            $('body').off('mousemove');
        })
    }
    $.fn.drag = function (dragobj, moveobj) {
        $('body').on('mousedown', '.treeBox', function (e) {
            if (e.target.className.indexOf(dragobj) != -1) {
                var mX = e.screenX,
                    mY = e.screenY;
                var strX = $(moveobj).css('left'),
                    strY = $(moveobj).css('top');
                var divX = /%/.test(strX) ? (e.screenX * (parseFloat(strX) / 100)) : parseFloat(strX) || 0,
                    divY = /%/.test(strY) ? (e.screenY * (parseFloat(strY) / 100)) : parseFloat(strY) || 0;
                var dX = mX - divX,
                    dY = mY - divY;
                $(this).css('cursor', 'move')
                $('body').on('mousemove', function (ev) {
                    $(moveobj).css({
                        'position': 'fixed',
                        'left': ev.screenX - dX + 'px',
                        'top': ev.screenY - dY + 'px',
                        'z-index': '999999'
                    })
                })
            }
        })
        $('body').on('mouseup', function (e) {
            $(this).css('cursor', 'auto')
            $('body').off('mousemove');
        })
    }
    $.fn.filterSearch = function () {
        var filterObj = {};
        $('.filter input:not(".search-xzqh-input")').each(function () {
            var value = $(this).val(),
                code = $(this).attr('data-code');
            if (value != '' && code != undefined) filterObj[code] = value;
        });
        $('.filter select:not(".xzqh")').each(function () {
            var value = $(this).find('option:selected').html(),
                code = $(this).attr('data-code');
            if ($(this).attr('data-text') == '建设性质') {
                if ($(this).hasClass('selectpicker')) {
                    var jsxzValue = $(this).next().find('.filter-option.pull-left').html();
                    filterObj[code] = jsxzValue == undefined ? '' : jsxzValue;
                } else {
                    filterObj[code] = $(this).find('option:selected').html()
                }
            } else {
                if (value != '' && code != undefined) {
                    if (code == 'do_things') {
                        var acId = localStorage.getItem('acId');
                        if (/(fomation)/.test(acId)) {
                            if (value == '待办') {
                                /change/.test(acId) ? filterObj['do_things'] = '已下达;未上报;财务未确认;不通过' : filterObj['do_things'] = '未上报;财务未确认;不通过'
                            } else if (value == '已办') {
                                filterObj['do_things'] = '未接收;中;退回;已下达';
                            }
                        } else if (/(first)/.test(acId)) {
                            if (value == '待办') {
                                filterObj['do_things'] = '初审未接收;初审中';
                            } else if (value == '已办') {
                                filterObj['do_things'] = '审查未接收;审查中;审核未接收;审核接收财务未确认;审核中;审核退回;审核通过审批未接收;审批中;审批退回;已下达';
                            }
                        } else if (/second/.test(acId)) {
                            if (value == '待办') {
                                filterObj['do_things'] = '审查未接收;审查中';
                            } else if (value == '已办') {
                                filterObj['do_things'] = '审核未接收;审核接收财务未确认;审核中;审核通过审批未接收;审批中;审批退回;已下达';
                            }
                        } else if (/third/.test(acId)) {
                            if (value == '待办') {
                                filterObj['do_things'] = '审核未接收;审核接收财务未确认;审核中';
                            } else if (value == '已办') {
                                filterObj['do_things'] = '审核通过审批未接收;审批中;已下达';
                            }
                        } else if (/forth/.test(acId)) {
                            if (value == '待办') {
                                filterObj['do_things'] = '审核通过审批未接收;审批中';
                            } else if (value == '已办') {
                                filterObj['do_things'] = '已下达';
                            }
                        } else if (/combine/.test(acId)) {
                            if (value == '待办') {
                                filterObj['do_things'] = '是否确认审核通过审批未接收';
                            } else if (value == '已办') {
                                filterObj['do_things'] = '审核通过审批未接收';
                            }
                        }
                        /(change)/.test(acId) ? filterObj['modified'] = '1' : filterObj['modified'] = '0';
                    } else {
                        if (code == 'PC' || code == 'XMLXDM' || code == 'XMAPFS' || code == 'SFFNDAPJH' || code == 'JHXZ' || code == 'XMLB') {
                            value = $(this).find('option:selected').val();
                        } else if (code == 'status') {
                            value = value.replace(/^(变更)/, '');
                            value.indexOf('变更') == -1 ? filterObj['modified'] = '0' : filterObj['modified'] = '1';
                        }
                        filterObj[code] = value;
                    }
                }
            }
        });
        if ($('.search-xzqh').length) {
            filterObj['XZQHMC'] = getxzqhCode('search-xzqh')[1];
        }
        if ($('.search-xzqh-input').length) {
            var code = $('.search-xzqh-input').attr('data-code');
            var value = $('.search-xzqh-input').attr('data-vercode');
            value == '1' ? '' : filterObj[code] = value;
        }
        return filterObj;
    }
    $.fn.searchBtn = function (numpage) {
        var method = {
            filterDo: function (acId, value, first, second, third, forth, status, m) {
                if (acId.indexOf('fomation') != -1) {
                    //编制
                    if (acId.indexOf('change_fomation') != -1) {
                        if (value == '待办') {
                            if (first != '') {
                                if (status != '变更初审退回' && status != '变更初审未接收' && status.indexOf('已下达') != -1 && status != '变更未上报' && status != '变更财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (second != '') {
                                if (status != '变更审查退回' && status != '变更审查未接收' && status.indexOf('已下达') != -1 && status != '变更未上报' && status != '变更财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status != '变更审核退回' && status != '变更审核未接收' && status.indexOf('已下达') != -1 && status != '变更未上报' && status != '变更财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        } else if (value == '已办') {
                            if (first != '') {
                                if (status == '变更初审退回' || status == '变更初审未接收' || status.indexOf('已下达') == -1 || status == '变更财务未确认' || status == '变更未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (second != '') {
                                if (status == '变更审查退回' || status == '变更审查未接收' || status.indexOf('已下达') == -1 || status == '变更财务未确认' || status == '变更未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status == '变更审核退回' || status == '变更审核未接收' || status.indexOf('已下达') == -1 || status == '变更财务未确认' || status == '变更未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        }
                    } else {
                        if (status.indexOf('变更') != -1) {
                            $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '待办') {
                            if (first != '') {
                                if (status != '初审退回' && status != '初审未接收' && status != '未上报' && status != '财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (second != '') {
                                if (status != '审查退回' && status != '审查未接收' && status != '未上报' && status != '财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status != '审核退回' && status != '审核未接收' && status != '未上报' && status != '财务未确认' && status.indexOf('不通过') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        } else if (value == '已办') {
                            if (first != '') {
                                if (status == '初审退回' || status == '初审未接收' || status == '财务未确认' || status == '未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (second != '') {
                                if (status == '审查退回' || status == '审查未接收' || status == '财务未确认' || status == '未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status == '审核退回' || status == '审核未接收' || status == '财务未确认' || status == '未上报' || status.indexOf('不通过') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        }
                    }
                } else if (acId.indexOf('trial_first') != -1) {
                    //初审
                    if (acId.indexOf('change') != -1) {
                        if (value == '待办') {
                            if (second != '') {
                                if (status != '变更审查退回' && status != '变更初审未接收' && status != '变更初审中') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status != '变更审核退回' && status != '变更初审未接收' && status != '变更初审中') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else {
                                if (status != '变更初审未接收' && status != '变更初审中' && status != '变更审查退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        } else {
                            if (second != '') {
                                if ((status.indexOf('审查') == -1 || status == '变更审查退回') && status.indexOf('已下达') == -1 && status.indexOf('审批') == -1 && status.indexOf('审核') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if ((status.indexOf('审核') == -1 || status == '变更审核退回') && status.indexOf('已下达') == -1 && status.indexOf('审批') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else {
                                if (status.indexOf('已下达') == -1 && status.indexOf('审批') == -1 && status.indexOf('审核') == -1 && (status.indexOf('审查') == -1 || status == '变更审查退回')) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        }
                    } else {
                        if (status.indexOf('变更') != -1) {
                            $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '待办') {
                            if (second != '') {
                                if (status != '审查退回' && status != '初审未接收' && status != '初审中') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if (status != '初审未接收' && status != '初审中' && status != '审核退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else {
                                if (status != '初审未接收' && status != '初审中' && status != '审查退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        } else if (status == '已办') {
                            if (second != '') {
                                if ((status.indexOf('审查') == -1 || status == '审查退回') && status.indexOf('已下达') == -1 && status.indexOf('审批') == -1 && status.indexOf('审核') != -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else if (third != '') {
                                if ((status.indexOf('审核') == -1 || status == '审核退回') && status.indexOf('已下达') == -1 && status.indexOf('审批') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            } else {
                                if (status.indexOf('已下达') == -1 && status.indexOf('审批') == -1 && status.indexOf('审核') == -1 && (status.indexOf('审查') == -1 || status == '审查退回')) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                            }
                        }
                    }
                } else if (acId.indexOf('trial_second') != -1) {
                    //审查
                    if (acId.indexOf('change') != -1) {
                        if (value == '待办') {
                            if (status != '变更审查未接收' && status != '变更审查中' && status != '变更审核退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '已办') {
                            if ((status.indexOf('审核') == -1 || status == '变更审核退回') && status.indexOf('审批') == -1 && status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    } else {
                        if (status.indexOf('变更') != -1) {
                            $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '待办') {
                            if (status != '审查未接收' && status != '审查中' && status != '审核退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '已办') {
                            if ((status.indexOf('审核') == -1 || status == '审核退回') && status.indexOf('审批') == -1 && status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    }
                } else if (acId.indexOf('trial_third') != -1) {
                    // 审核
                    if (acId.indexOf('change') != -1) {
                        if (value == '待办') {
                            if (status != '变更审核未接收' && status != '变更审核接收财务未确认' && status != '变更审核中' && status != '变更审批退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else {
                            if ((status.indexOf('审批') == -1 || status == '变更审批退回') && status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    } else {
                        if (status.indexOf('变更') != -1) {
                            $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '待办') {
                            if (status != '审核未接收' && status != '审核接收财务未确认' && status != '审核中' && status != '审批退回') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else {
                            if ((status.indexOf('审批') == -1 || status == '审批退回' || status == '是否确认审核通过审批未接收') && status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    }
                } else if (acId.indexOf('trial_forth') != -1) {
                    // 审批
                    if (acId.indexOf('change') != -1) {
                        if (value == '待办') {
                            if (status != '变更审核通过审批未接收' && status != '变更审批中') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else {
                            if (status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    } else {
                        if (status.indexOf('变更') != -1) {
                            $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else if (value == '待办') {
                            if (status != '审核通过审批未接收' && status != '审批中') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        } else {
                            if (status.indexOf('已下达') == -1) $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                        }
                    }
                } else if (acId == 'road_combine') {
                    // 子项目整合
                    if (value == '待办') {
                        if (status != '是否确认审核通过审批未接收') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                    } else {
                        if (status == '是否确认审核通过审批未接收') $('.data-table tbody>tr:nth-child(' + (m + 1) + ')').addClass('unsearchTd');
                    }
                }
            },
            filterTbody: function (val, valText) {
                var theadAr = getThead()[0];
                if (valText == '待办事宜') {
                    var larr = top.location.pathname.split('.')[0].split('/'),
                        type = larr[larr.length - 1];
                    // 获取tbody>td的值
                    var tbody = trChildren($('.data-table tbody>tr')),
                        trArray = tbody.trArray,
                        tdContentobj = tbody.trChildrenobj;
                    for (var m = 0; m < trArray.length; m++) {
                        var acId = localStorage.acId,
                            value = $('.things option:selected').val(),
                            status = tdContentobj[m][1];
                        status = status.split('/')[1] == undefined ? status : status.split('/')[1].split('-')[1];
                        if (type == 'tl' || type == 'gs' || type == 'gsd' || type == 'sy' || type == 'zc' || type == 'jc' || type == 'wngl') {
                            method.filterDo(acId, value, tdContentobj[m][5], tdContentobj[m][6], tdContentobj[m][7], tdContentobj[m][8], status, m);
                        } else if (type == 'gljy' || type == 'syjy' || type == 'zcxt' || /^(nc)/.test(type)) {
                            method.filterDo(acId, value, tdContentobj[m][7], tdContentobj[m][8], tdContentobj[m][9], tdContentobj[m][10], status, m);
                        } else if (/^(sj)/.test(type)) {
                            method.filterDo(acId, value, tdContentobj[m][6], tdContentobj[m][7], tdContentobj[m][8], tdContentobj[m][9], status, m);
                        }
                    }
                }
                for (var a in theadAr) {
                    if (theadAr[a].indexOf(valText) != -1) {
                        var index = parseInt(a);
                        // 获取tbody>td的值
                        var tbody = trChildren($('.data-table tbody>tr'));
                        var trArray = tbody.trArray;
                        var tdContentobj = tbody.trChildrenobj;
                        // 判断val是否为数组？
                        if (val instanceof Array) {
                            for (var m in val) {
                                for (var i = 0; i < trArray.length; i++) {
                                    if (val.length == 1) {
                                        if (tdContentobj[i][index] != val[m]) {
                                            $('.data-table tbody>tr:nth-child(' + (i + 1) + ')').addClass('unsearchTd');
                                        }
                                    } else {
                                        var re = new RegExp('' + val[m] + '', 'gim');
                                        if (!re.test(tdContentobj[i])) {
                                            $('.data-table tbody>tr:nth-child(' + (i + 1) + ')').addClass('unsearchTd');
                                        }
                                    }
                                }
                            }
                        } else {
                            for (var e = 0; e < trArray.length; e++) {
                                if (valText == '项目名称') {
                                    if (tdContentobj[e][index].indexOf(val) == -1) $('.data-table tbody>tr:nth-child(' + (e + 1) + ')').addClass('unsearchTd');
                                } else if (valText == '状态') {
                                    var statusAll = tdContentobj[e][index];
                                    statusAll = statusAll.split('/')[1] == undefined ? statusAll : statusAll.split('/')[1].split('-')[1];
                                    if (statusAll != val) $('.data-table tbody>tr:nth-child(' + (e + 1) + ')').addClass('unsearchTd');
                                } else {
                                    if (tdContentobj[e][index] != val) $('.data-table tbody>tr:nth-child(' + (e + 1) + ')').addClass('unsearchTd');
                                }
                            }
                        }
                    }
                }
            }
        }
        var obj = {},
            objText = {},
            jIndex = 0;
        var inputLength = $('.filter input').length;
        $('.filter input:not(".search-xzqh-input")').each(function (a) {
            obj[a] = this.value;
            objText[a] = $(this).attr('data-text');
        });
        $('.filter select:not(".xzqh")').each(function (b) {
            var className = $(this).attr('class');
            jIndex = inputLength + b;
            if ($(this).attr('data-text') == '建设性质') {
                var jsxzValue = $(this).next().find('.filter-option.pull-left').html();
                jsxzValue == undefined ? obj[jIndex] = $(this).find('option:selected').html() : (obj[jIndex] = jsxzValue == '请选择' ? '' : jsxzValue);
            } else {
                obj[jIndex] = $(this).find('option:selected').html();
            }
            objText[jIndex] = $(this).attr('data-text');
        });
        if ($('.search-xzqh').length) {
            obj[jIndex + 1] = getxzqhCode('search-xzqh')[1];
            objText[jIndex + 1] = '行政区划';
        }
        if ($('.search-xzqh-input').length) {
            obj[jIndex + 1] = $('.search-xzqh-input').attr('data-vercode');
            objText[jIndex + 1] = '行政区划';
        }
        var bool = false;
        for (var i in obj) {
            if (obj[i] != '' && obj[i] != null) {
                method.filterTbody(obj[i], objText[i]);
                bool = true;
            }
        }
        //符合
        if (bool) {
            $('.data-table tbody>tr').each(function (i) {
                if (!$(this).hasClass('unsearchTd')) {
                    $(this).addClass('searchTd');
                } else if (!$(this).hasClass('searchTd')) {
                    $(this).addClass('unsearchTd');
                }
            });
            $('#myTable').fixTable(4);
            var lenShow = $('.data-table tbody>tr.searchTd').length,
                totallyNum = Math.ceil(lenShow / numpage);
            var everyPage = lenShow > numpage ? numpage : lenShow;
            $('.inputsTyle').eq(2).val(everyPage);  //每页显示条数
            $(".pageTotally").val(totallyNum);  //总页数
            $('.inputsTyle').eq(4).val(lenShow);  //总条数
        }
    }
    $.fn.clear = function (numpage) {
        $('.data-table tbody>tr').removeClass('unsearchTd').removeClass('searchTd');
        $('.filter input').val('');
        //重置所有select
        for (var i in $('.filter select')) {
            $('.filter select')[i].selectedIndex = 0;
        }
        $('.dropdown-menu.selectpicker').find('li').removeClass('selected').eq(0).addClass('selected');
        $('.selectpicker').selectpicker('val', ['']);
        $('.inp_division_1').attr('data-vercode', '');
        getProject(everyNum, 1);
    }
    $.fn.fixTable = function (FixColumnNumber) {
        var $this = $(this);
        var height = $this.height();
        $('.fixColumn').length ? $('.fixColumn').remove() : '';
        $this.after($('<div class="fixColumn"/>'))
        var bodyTr = '',
            bodyTd = '',
            headTh = '';
        var btr = $this.children('tbody').children();
        var htr = $this.children('thead').children();
        var trLength = btr.length;
        var fixWidth;
        var headHeight;
        var method = {
            dblDo: function ($this) {
                timer && clearTimeout(timer);
                var bool = false;
                var project_id = $this.attr('data-id');
                if ($('#userTable').length) {
                    var user_name = $('#userTable tbody>tr.active').attr('data-id');
                    editPeople(user_name);
                } else {
                    var trActive = $('#myTable tbody tr.active');
                    if ($this.hasClass('forbidden')) {
                        alertMs('你没有操作' + $this.children().eq(2).html() + '的权限');
                    }
                    editMatch(project_id);
                }
                $('.btnBox').hide();
                $('#myModalgh').modal('show');
                $('#ghxzModal').find('input').attr('readonly', 'true');
                $('#ghxzModal').find('select, textarea').attr('disabled', 'disabled');
                $('#jhInfo').addClass('modalActive').siblings().removeClass('modalActive');
                $('#ghxzModal').show().siblings().hide();
                $('#ghcs,#ghsc,#ghsh,#ghsp').css('display', 'none');
                var thistatus = $this.children().eq(1).html();
                for (var m = 0; m < data.length; m++) {
                    if (data[m].identifier == project_id) {
                        if (localStorage.acId.indexOf('fomation') != -1) {
                            if (localStorage.user_right == 'trial_third' && decodeURI(data[m]['status']) == '审核未接收') {
                                bool = false;
                            } else if (localStorage.user_right == 'trial_second' && decodeURI(data[m]['status']) == '审查未接收') {
                                bool = false;
                            } else if (localStorage.user_right == 'trail_first' && decodeURI(data[m]['status']) == '初审未接收') {
                                bool = false;
                            }
                        } else if (localStorage.division_code == data[m]['to_division'] && decodeURI(localStorage.career) == decodeURI(data[m]['to_career']) && !$this.hasClass('forbidden')) {
                            bool = true;
                        }
                    }
                }
                if (bool) {
                    if (thistatus.indexOf('初审未接收') != -1) {
                        changeStatus(project_id, '初审中', function () {
                            $this.children().eq(1).html(thistatus.replace(/(初审未接收)/, '初审中'));
                        });
                    } else if (thistatus.indexOf('审查未接收') != -1) {
                        changeStatus(project_id, '审查中', function () {
                            $this.children().eq(1).html(thistatus.replace(/(审查未接收)/, '审查中'));
                        });
                    } else if (thistatus.indexOf('审核未接收') != -1) {
                        if ($('#myTable').hasClass('sj-table') || $('#myTable').hasClass('nc-table') || $('#myTable').hasClass('bj-table')) {
                            changeStatus(project_id, '审核接收财务未确认', function () {
                                $this.children().eq(1).html(thistatus.replace(/(审核未接收)/, '审核接收财务未确认'));
                            })
                        } else {
                            changeStatus(project_id, '审核中', function () {
                                $this.children().eq(1).html(thistatus.replace(/(审核未接收)/, '审核中'));
                            });
                        }
                    } else if (thistatus.indexOf('审核通过审批未接收') != -1) {
                        changeStatus(project_id, '审批中', function () {
                            $this.children().eq(1).html(thistatus.replace(/(审核通过审批未接收)/, '审批中'));
                        });
                    }
                    $('#myTable').fixTable(4);
                }
                $('.soureAdd').on('click', function () {
                    alertMs('查看时不能进行新增操作');
                    return false;
                });
                $('.soureDel,.addDel').on('click', function () {
                    alertMs('查看时不能进行删除操作');
                    return false;
                });
                $('.xzform').hide();
                $('.fileUp').on('click', function () {
                    alertMs('查看时不能进行上传操作');
                    return false;
                });
                $('.addLoad,.csLoad,.scLoad,.shLoad,.csDel').on('click', function () {
                    alertMs('查看时不能进行下载操作');
                    return false;
                })
            }
        }
        for (var j = 0; j < trLength; j++) {
            fixWidth = 0;
            headTr = '';
            bodyTd = '';
            headTh = '';
            for (var i = 0; i < FixColumnNumber; i++) {
                bodyTd += btr.eq(j).children().eq(i).prop("outerHTML");
                headTh += htr.children().eq(i).prop("outerHTML");
                fixWidth += btr.children().eq(i).outerWidth();
            }
            bodyTr += "<tr class='" + ((btr.eq(j).hasClass('none') || btr.eq(j).hasClass('unsearchTd')) ? 'none' : '') + "'>" + bodyTd + "</tr>";
        }
        headHeight = $this.children('thead').height();
        var table = $("<table class='fixtable table-container'>" +
            "<thead><tr style=\"height:" + headHeight + "px;\">" + headTh + "</tr></thead>" +
            "<tbody>" +
            bodyTr +
            "</tbody>" +
            "</table>");
        $this.parent().css('position', 'relative');
        $('.fixColumn').append(table);
        $('.fixColumn').css({
            'position': 'absolute',
            'left': $(this).scrollLeft() + 15 + 'px',
            'top': 0,
            'width': fixWidth + 'px',
            'height': height + 'px',
            'background-color': '#fff',
            'display': 'none'
        })
        $('.fixtable').css({
            'width': fixWidth + 'px',
            'height': height + 'px',
        })
        $this.parent().on('scroll', function () {
            var left = $(this).scrollLeft();
            left > 0 ? $('.fixColumn').show() : $('.fixColumn').hide();
            $('.fixColumn').css('left', left + 15 + 'px');
        })
        $('.fixtable').on('click.fix', 'tr', function (e) {
            var index = $(this).index();
            var $thisTr = $this.children('tbody').children().eq(index);
            if (e.target.tagName.toLowerCase() == 'input') {
                $(this).children().eq(0).children().is(':checked') ?
                    $thisTr.children().eq(0).children().attr('checked', 'true') :
                    $thisTr.children().eq(0).children().removeAttr('checked');
            } else {
                $(this).hasClass('active') ?
                    ($(this).removeClass('active'), $thisTr.removeClass('active')) :
                    ($(this).addClass('active').siblings().removeClass('active'), $thisTr.addClass('active').siblings().removeClass('active'));
            }
            $('.inputsTyle').eq(3).val(index + 1);
        }).on('dblclick', 'tr', function () {
            var index = $(this).index();
            method.dblDo($('#myTable tbody>tr').eq(index));
        })
        $._data($this[0], "events") ? '' : $this.on('click', 'tr', function (e) {
            var $this = $(this);
            timer && clearTimeout(timer);
            timer = setTimeout(function () {
                var index = $this.index();
                var thisTr = $('.fixtable').children('tbody').children().eq(index);
                if (e.target.tagName.toLowerCase() == 'input') {
                    $this.children().eq(0).children().is(':checked') ?
                        thisTr.children().eq(0).children().attr('checked', 'true') :
                        thisTr.children().eq(0).children().removeAttr('checked');
                } else {
                    $this.hasClass('active') ?
                        ($this.removeClass('active'), thisTr.removeClass('active')) :
                        ($this.addClass('active').siblings().removeClass('active'), thisTr.addClass('active').siblings().removeClass('active'));
                }
                $('.inputsTyle').eq(3).val(index + 1);
            }, 100);
        }).on('dblclick', 'tr', function () {
            method.dblDo($(this));
        });
    }
})(jQuery)


//获取项目后
function getResult(result, currentPage) {
    data = [];
    totalNum = result['total_num'];
    var list = result['list'];
    var total = result['total'];
    $.each(list, function (key, value) {
        var obj = {};
        $.each(value, function (k, v) {
            if (k == 'content') {
                $.each(v, function (ki, vi) {
                    obj[ki] = vi;
                })
            } else {
                obj[k] = v;
            }
        })
        data.push(obj);
    });
    if (total != undefined) {
        data.push(total);
    }
    $.pageQuery(currentPage, everyNum);

    $.selectTab();
    $.division('.inp_division_1', '.treeBox_1', '.divisionIcon1');
    $.division('.inp_division_3', '.treeBox_1', '.divisionIcon3');
    $.division('.inp_division_4', '.treeBox_3', '.divisionIcon4');
    $.division('.inp_division_5', '.treeBox_4', '.divisionIcon5');
    approve('.divisionIcon2');
    $.versionSee();
    $.newAddSubmit();
    $.firstTrial('.inp_division_2', '.divisionIcon2');
    $('.addIcon').on('click.add', function () {
        $.contentWri();
        autoCode();
    });
    $.tableEvent();
    $.cityChange();
    $.yearAuto(new Date().getFullYear());
}

//改变项目status状态
function changeStatus(id, thestatus, callback) {
    $.post('/api/enrol_project?project_id=' + id + '&status=' + encodeURI(thestatus) + '&user_name=' + localStorage.user_name, {}, function () {
        callback()
    })
}

//转换中文地址至行政区划代码
function toDevision(thelocation) {
    var turncode = '330000';
    $.each(devisionc, function (key, value) {
        if (thelocation == value) {
            turncode = key;
        }
    })
    return turncode
}

//切换modal
function approveModal(id, dataId, txt) {
    // var dataId = $('.data-table tbody>tr.active').attr('data-id');
    var first_trial = '',
        second_trial = '',
        third_trial = '',
        status = '';
    for (var a in data) {
        if (data[a]['identifier'] == dataId) {
            first_trial = data[a]['first_trial'];
            second_trial = data[a]['second_trial'];
            third_trial = data[a]['third_trial'];
            status = decodeURI(data[a]['status']);
        }
    }
    $.capitalSoure();
    $.soureDel();
    //下载
    $('.addLoad').off('click').on('click', function () {
        $.fileDownLoad('.file_add');
    });
    $('.csLoad').off('click').on('click', function () {
        $.fileDownLoad('.file_cs');
    });
    $('.scLoad').off('click').on('click', function () {
        $.fileDownLoad('.file_sc');
    });
    $('.shLoad').off('click').on('click', function () {
        $.fileDownLoad('.file_sh');
    });
    $('.op-download').off('click').on('click', function () {
        var that = $(this);
        $.fileDownLoad('.file_bb', that);
    });
    //删除
    $('.addDel').off('click').on('click', function () {
        $.fileDel('.file_add');
    });
    $('.csDel').off('click').on('click', function () {
        $.fileDel('.file_cs');
    });
    $('.scDel').off('click').on('click', function () {
        $.fileDel('.file_sc');
    });
    $('.shDel').off('click').on('click', function () {
        $.fileDel('.file_sh');
    });
    $('.JHWYBM').off('change').on('change', function () {
        var value = $(this).val();
        $('.JHWYBM').val(value);
    });
    if (id != 'bj') $.getJyAlready();
    if (pline != null) maplet.removeOverlay(pline);
    $('.btnBox').show();
    $('#myModalgh').find('input').attr('readonly', false);
    $('#myModalgh').find('select, textarea').attr('disabled', false);
    $('.orgazition,.date,.XMBM-auto,.XZQH,.third_trial,.first_trial').attr('readonly', true);
    $('.fm-basic p,.fm-approve p').html('');
    $('.fm-basic-content,.fm-approve-content').empty();
    $('.xmfm-container').hide();
    $('.selected-container tbody,.kzd-table tbody').empty();
    $('.confirmBtn').eq(0).removeAttr('data-type');
    $('.issued-career').addClass('none');
    $('.issued-career input').attr('data-code', '');
    $('.issued-career input').attr('data-career', '');
    var provinceArr = ['交通运输厅', '公路局', '港航局', '运管局', '机场局', '浙江交院', '省交通干部学校', '技师学院', '厅信息中心', '咨询监理公司', '交科院', '交通工程监管局'];
    if (localStorage.division_code == '330000' && $.inArray(localStorage.career, provinceArr) != -1) $('#ghxzModal .second_trial').attr('disabled', true);
    if (localStorage.getItem('acId') == 'road_combine') {
        $('#jhInfo').html('母项目').addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghitem,#ghitemModal').show();
        $('#ghxzModal').show().siblings().hide();
        $('#ghitemSelect,#ghitemAdd').hide();
        $('.XMBM-auto').attr('readonly', true);
    }
    if ($('#myMap').length > 0) {
        mapPolyline();
    }
    switch (id) {
        case 'xz': //新增
            $('.xgBtn,#ghitemSelect,#ghitemAdd,#ghitemEdit').hide();
            $('.xzBtn').show();
            $('#jhInfo').addClass('modalActive').siblings().removeClass('modalActive');
            //清空已填数据
            $('#ghxzModal').find('input:not(".jmdInput,.jbxzqh,.TBDWDM,.TBDWMC,.XMTBRDWDM,.XMTBRDWMC")').val('');
            $('#ghxzModal').find('textarea').val('');
            $('#ghxzModal .third_trial').val('浙江省/交通运输厅');
            $('#ghxzModal').find('select:not(".jqqx")').val('');
            sessionStorage.removeItem('mapArray');
            $('.JHNF').val(new Date().getFullYear());
            $('#myModalgh .fjContainer tbody').empty();
            $('.tableWrap').hide();
            $('.routeConstruct').addClass('none');
            $('#myModalgh .dropdown-menu.selectpicker').find('li').removeClass('selected').removeClass('active').eq(0).addClass('selected');
            $('#myModalgh .selectpicker').selectpicker('val', ['']);
            break;
        case 'xg': //修改
            switch (status) {
                case '初审退回': case '初审不通过':
                    $('#ghcs').css('display', 'inline');
                    break;
                case '审查退回': case '审查不通过':
                    if (!!first_trial) $('#ghcs').css('display', 'inline');
                    $('#ghsc').css('display', 'inline');
                    break;
                case '审核退回': case '审核不通过':
                    $('#ghsh').css('display', 'inline');
                    if (!!first_trial) $('#ghcs').css('display', 'inline');
                    if (!!second_trial) $('#ghsc').css('display', 'inline');
                    break;
                case '审批退回': case '审批不通过':
                    $('#ghsp').css('display', 'inline');
                    if (!!first_trial) $('#ghcs').css('display', 'inline');
                    if (!!second_trial) $('#ghsc').css('display', 'inline');
                    if (!!third_trial) $('#ghsh').css('display', 'inline');
                    break;
                default:
                    break;
            }
            $('.xgBtn').show();
            $('.xzBtn,#ghitemSelect').hide();
            if (localStorage.getItem('acId') == 'road_combine') {
                $('#jhInfo').html('母项目').addClass('modalActive').siblings().removeClass('modalActive');
                $('#ghitem,#ghitemModal').show();
                $('#ghxzModal').show().siblings().hide();
            }
            editMatch(dataId, txt);
            break;
        case 'cs': //初审
            $('#ghcs').css('display', 'inline');
            $('.xgBtn').show();
            $('.xzBtn').hide();
            $('#gh' + id + 'Modal .second_trial').attr('disabled', 'disabled');
            $('#gh' + id + 'Modal .third_trial').attr('readonly', true);
            trailVal('cs', dataId);
            break;
        case 'sc': //审查
            $('#ghsc').css('display', 'inline');
            if (!!first_trial) $('#ghcs').css('display', 'inline') && $('#ghcsModal .btnBox').hide();
            $('#gh' + id + 'Modal .second_trial').attr('disabled', 'disabled');
            $('#gh' + id + 'Modal .third_trial').attr('readonly', true);
            $('.xgBtn').show();
            $('.xzBtn').hide();
            trailVal('sc', dataId);
            $('#ghcsModal').find('input').attr('readonly', true);
            $('#ghcsModal').find('select, textarea').attr('disabled', 'disabled');
            break;
        case 'sh': //审核
            $('#ghsh').css('display', 'inline');
            if (!!first_trial) $('#ghcs').css('display', 'inline') && $('#ghcsModal .btnBox').hide();
            if (!!second_trial) $('#ghsc').css('display', 'inline') && $('#ghscModal .btnBox').hide();
            $('#gh' + id + 'Modal .second_trial').attr('disabled', 'disabled');
            $('#gh' + id + 'Modal .third_trial').attr('readonly', true);
            $('.xgBtn').show();
            $('.xzBtn').hide();
            trailVal('sh', dataId);
            $('#ghcsModal,#ghscModal').find('input').attr('readonly', true);
            $('#ghcsModal,#ghscModal').find('select, textarea').attr('disabled', 'disabled');
            break;
        case 'sp': //审批
            $('#ghsp').css('display', 'inline');
            if (!!first_trial) $('#ghcs').css('display', 'inline') && $('#ghcsModal .btnBox').hide();
            if (!!second_trial) $('#ghsc').css('display', 'inline') && $('#ghscModal .btnBox').hide();
            if (!!third_trial) $('#ghsh').css('display', 'inline') && $('#ghshModal .btnBox').hide();
            $('#gh' + id + 'Modal .second_trial').attr('disabled', 'disabled');
            $('#gh' + id + 'Modal .third_trial').attr('readonly', true);
            $('.xgBtn').show();
            $('.xzBtn').hide();
            trailVal('sp', dataId);
            $('#ghcsModal,#ghscModal,#ghshModal').find('input').attr('readonly', true);
            $('#ghcsModal,#ghscModal,#ghshModal').find('select, textarea').attr('disabled', 'disabled');
            break;
        case 'bj':
            $('#myModalgh').find('input:not(".jmdInput"),textarea,select').val('');
            $('.bodyObj').addClass('none');
            editMatch(dataId, txt);
            break;
        default:
            break;
    }
    $('#gh' + id).addClass('modalActive').siblings().removeClass('modalActive');
    $('#gh' + id + 'Modal').show().siblings().hide();
    $('#jhInfo').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghxzModal').show().siblings().hide();
        if (id != 'xz') {
            editMatch(dataId);
            $('.xgBtn').show();
            $('#ghitemSelect,#ghitemAdd,#ghitemEdit,.xzBtn').hide();
        } else {
            $('.xzBtn').show();
            $('#ghitemSelect,#ghitemAdd,#ghitemEdit,.xgBtn').hide();
            //清空已填数据
            $('#ghxzModal').find('input:not(".jmdInput,.jbxzqh,.XMTBRDWDM,.XMTBRDWMC")').val('');
            $('#ghxzModal').find('textarea').val('');
            $('#ghxzModal .third_trial').val('浙江省/交通运输厅');
            sessionStorage.removeItem('mapArray');
            $('.JHNF').val(new Date().getFullYear());
            $('#myModalgh .fjContainer tbody').empty();
            $('.tableWrap').hide();
            $('.routeConstruct').addClass('none');
        }
        $('.confirmBtn').eq(0).removeAttr('data-type');
        $('.confirmBtn').eq(1).removeAttr('data-type');
        $('.issued-career').addClass('none');
        $('.issued-career input').attr('data-code', '');
        $('.issued-career input').attr('data-career', '');
        $('.confirmBtn').attr('disabled', false);
    });
    $('#ghcs').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghcsModal').show().siblings().hide();
        trailVal('cs', dataId);
    });
    $('#ghsc').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghscModal').show().siblings().hide();
        trailVal('sc', dataId);
    });
    $('#ghsh').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghshModal').show().siblings().hide();
        trailVal('sh', dataId);
    });
    $('#ghsp').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghspModal').show().siblings().hide();
        trailVal('sp', dataId);
    });
    $('#ghitem').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghitemModal').show().siblings().hide();
        $('#ghitemSelect,#ghitemAdd,#ghitemEdit').hide();
    });
    $('#ghitemAdd').click(function () {
        $(this).addClass('modalActive').siblings().removeClass('modalActive');
        $('#ghxzModal').show().siblings().hide();
    });
}

//获取相应机构
function getOrg(trial) {
    var astr = '';
    var reg = trial.match(/\d{6}/)[0];
    astr = devisionc[reg];
    var trialCode = trial.replace(/\d{6}/, astr + '/');
    return trialCode;
}

//审字段获取
function trial(id, projectId, txt) {
    var datan = {};
    datan.suggest = $('#gh' + id + 'Modal .suggest').val();
    datan.result = $('#gh' + id + 'Modal .result option:selected').val();
    datan.date = $('#gh' + id + 'Modal .date').val();
    if ($('#gh' + id + 'Modal .result option:selected').val() == '') {
        alertMs('请选择' + txt + '结果');
    }
    // 批复/下达文件
    var fileTbody = trChildren($('#gh' + id + 'Modal .approve_file tbody>tr'));
    datan.approve_file = fileTbody.trChildrenobj;
    datan.first_trial = $('#gh' + id + 'Modal .first_trial').attr('data-vercode') + $('#gh' + id + 'Modal .first_trial').attr('data-vername');
    var second = $('#gh' + id + 'Modal .second_trial option:selected').val();
    datan.second_trial = second == '' ? '' : $('#gh' + id + 'Modal .second_trial option:selected').val() + $('#gh' + id + 'Modal .second_trial option:selected').attr('data-vername');
    datan.third_trial = '330000交通运输厅';
    datan.forth_trial = '330000交通运输部';
    return datan;
}

//审字段赋值
function trailVal(id, dataId) {
    $('#gh' + id + 'Modal').find('input').val('');
    if (!$('.second_trial')) {
        $('#gh' + id + 'Modal').find('select').val('');
    };
    var index = 0;
    for (var i in data) {
        if (data[i].identifier == dataId) index = parseInt(i);
    }
    var first_trial = '',
        second_trial = '',
        third_trial = '',
        forth_trial = '';
    var first_trial_code = data[index].first_trial,
        second_trial_code = data[index].second_trial,
        third_trial_code = data[index].third_trial,
        forth_trial_code = data[index].forth_trial;
    if (first_trial_code != '') first_trial = getOrg(first_trial_code);
    if (second_trial_code != '') second_trial = getOrg(second_trial_code);
    if (third_trial_code != '') third_trial = getOrg(third_trial_code);
    if (forth_trial_code != '') forth_trial = getOrg(forth_trial_code);
    var second_name = second_trial.split('/')[1],
        trial = '';
    switch (id) {
        case 'cs':
            trial = data[index].trial_first;
            $('#gh' + id + 'Modal .orgazition').val(first_trial);
            break;
        case 'sc':
            trial = data[index].trial_second;
            $('#gh' + id + 'Modal .orgazition').val(second_trial);
            break;
        case 'sh':
            trial = data[index].trial_third;
            $('#gh' + id + 'Modal .orgazition').val(third_trial);
            break;
        case 'sp':
            trial = data[index].trial_forth;
            $('#gh' + id + 'Modal .orgazition').val(forth_trial);
            break;
        default:
            break;
    }

    $('#gh' + id + 'Modal .suggest').val(trial.suggest);
    $('#gh' + id + 'Modal .result').val(trial.result);

    if (!!trial.date) {
        $('#gh' + id + 'Modal .date').val(trial.date);
    } else {
        $('#gh' + id + 'Modal .date').val(getDate(1));
    }
    //批复/下达文件
    $('#gh' + id + 'Modal .approve_file tbody').empty();
    var fileObj = trial.approve_file,
        fileTd = '';
    for (var a in fileObj) {
        //文件类型
        var filelx = fileObj[a][2];
        var filelxSelect = '<select><option value="">-请选择-</option><option>公可相关</option><option>初设相关</option><option>其他</option></select>';
        if (filelx != '') {
            var reg = '>' + filelx + '';
            filelxSelect = filelxSelect.replace(reg, ' selected' + reg);
        }
        fileTd += '<tr><td>' + fileObj[a][0] + '</td><td>' + fileObj[a][1] + '</td><td class="fileType">' + filelxSelect + '</td><td><input type="text" class="fileInp" value="' + fileObj[a][3] + '"></td><td>' + fileObj[a][4] + '</td><td>' + fileObj[a][5] + '</td></tr>';
    }
    $('#gh' + id + 'Modal .second_trial option').each(function (a) {
        if ($(this).attr('data-vername') == second_name) {
            $(this).prop('selected', true);
            return false;
        }
    });
    $('#gh' + id + 'Modal .approve_file tbody').empty().append(fileTd);
    $('#gh' + id + 'Modal .first_trial').val(first_trial);
    if (!!first_trial) $('#gh' + id + 'Modal .first_trial').attr({ 'data-vercode': toDevision(first_trial.split('/')[0]), 'data-vername': first_trial.split('/')[1] });
    $('#gh' + id + 'Modal .third_trial').val(third_trial);
    $('#gh' + id + 'Modal .third_trial').attr({ 'data-vercode': toDevision(third_trial.split('/')[0]), 'data-vername': third_trial.split('/')[1] });
}

function getDate(type) {
    //日期
    var myDate = new Date(),
        m = myDate.getMonth() + 1;
    if (m < 10) {
        m = '0' + m;
    }
    var d = myDate.getDate();
    if (d < 10) {
        d = '0' + d;
    }
    var time = '';
    type ? time = myDate.getFullYear() + "-" + m + "-" + d : time = myDate.getFullYear() + "-" + m + "-" + d + ' ' + myDate.getHours() + ':' + myDate.getMinutes() + ':' + myDate.getSeconds();
    return time;
}

function trChildren(trarray) {
    var tdText = [],
        tdArray = [],
        tdContent = {};
    if (trarray.length > 0) {
        for (var i = 0; i < trarray.length; i++) {
            tdText = trarray.eq(i).children();
            for (var j = 0; j < tdText.length; j++) {
                if (tdText[j].children[0] != undefined) {
                    tdArray.push(tdText[j].children[0].value);
                } else {
                    tdArray.push(tdText[j].innerText);
                }

            }
            tdContent[i] = tdArray;
            tdArray = [];
        }
    }
    return {
        'trArray': trarray,
        'trChildrenobj': tdContent
    };
}

var xhrOnProgress = function (fun) {
    xhrOnProgress.onprogress = fun; //绑定监听函数
    return function () {
        var xhr = $.ajaxSettings.xhr();
        if (xhrOnProgress.onprogress == null || typeof xhrOnProgress.onprogress === 'undefined')
            return xhr;
        if (xhrOnProgress.onprogress && xhr.upload) {
            xhr.upload.onprogress = xhrOnProgress.onprogress;
        }
        return xhr;
    }
};

$.extend({
    createTr: function (obj, currentPage, everyNumber) {
        var trStr = '';
        var tableArr = getThead()[1];
        var division = localStorage.getItem('division_code'),
            career = localStorage.getItem('career');
        for (var i = 0; i < obj.length; i++) {
            var tdStr = "",
                status = decodeURI(obj[i]['status']);
            var xh = parseInt(currentPage - 1) * 10 + i + 1;
            if (obj[i]['modified'] == undefined) {
                //历年项目
                for (var j = 0, len = tableArr.length; j < len; j++) {
                    if (tableArr[j] == 'xh') {
                        tdStr += "<td>" + xh + "</td>";
                    } else {
                        var inside = '',
                            str = tableArr[j];
                        for (var k in obj[i]) {
                            var theobj = obj[i][k];
                            if (k == 'TABLE_LWGSGC') {
                                if (theobj[tableArr[j]] == undefined) {
                                    inside = "<td></td>";
                                } else {
                                    inside = "<td>" + theobj[tableArr[j]] + "</td>";
                                }
                            } else if (theobj.hasOwnProperty(str)) {
                                inside = "<td>" + theobj[tableArr[j]] + "</td>";
                                break;
                            }
                        }
                        tdStr += inside;
                    }
                }
                (division == '330000' && career == '交通运输厅') ? trStr += "<tr data-id=\"" + obj[i]['XMID'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['XMID'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
            } else {
                for (var j = 0, len = tableArr.length; j < len; j++) {
                    if ((tableArr[j] == "first_trial" || tableArr[j] == "up_org" || tableArr[j] == "second_trial" || tableArr[j] == "third_trial" || tableArr[j] == "forth_trial" || tableArr[j] == 'issued_career') && /\d{6}/.test(obj[i][tableArr[j]])) {
                        var astr = '';
                        var reg = obj[i][tableArr[j]].match(/\d{6}/)[0];
                        astr = devisionc[reg];
                        //如果值为"undefined"则为空
                        if (obj[i][tableArr[j]].replace(/\d{6}/, astr + '/').indexOf('undefined') != -1) {
                            obj[i][tableArr[j]] = '';
                        }
                        tdStr += "<td>" + obj[i][tableArr[j]].replace(/\d{6}/, astr + '/') + "</td>";
                    } else if (tableArr[j] == 'status') {
                        var statusOrg = '';
                        if (status == '财务未确认' || status == '未上报') {
                            statusOrg = devisionc[obj[i]['up_org'].substr(0, 6)] + '/' + obj[i]['up_org'].substring(6, obj[i]['up_org'].length);
                        } else {
                            statusOrg = devisionc[obj[i]['to_division']] + '/' + obj[i]['to_career']
                        }
                        if (obj[i]['modified'] == '1') {
                            status == '已下达' ? tdStr += "<td>变更" + status + "</td>" : tdStr += "<td>" + statusOrg + '-变更' + status + "</td>";
                        } else {
                            status == '已下达' ? tdStr += "<td>" + status + "</td>" : tdStr += "<td>" + statusOrg + '-' + status + "</td>";
                        }
                    } else {
                        if (obj[i][tableArr[j]] != undefined) {
                            tdStr += "<td>" + obj[i][tableArr[j]] + "</td>";
                        } else {
                            var inside = '';
                            var str = tableArr[j];
                            if (obj[i]['TABLE_JMDXX'] == undefined) {
                                if (str == 'JMDMC' || str == 'JMDBM' || str == 'JMDLXHY' || str == 'TDZKHY') {
                                    inside = '<td></td>';
                                }
                            }
                            for (var k in obj[i]) {
                                if (k != 'history') {
                                    var theobj = obj[i][k];
                                    if (!!data[i]['TABLE_DKJSGM'] && !!data[i]['TABLE_QLJSGM']) {
                                        if (theobj instanceof Object) {
                                            if (theobj == {} || theobj == '') {
                                                inside = '<td></td>';
                                            } else if (str in theobj) {
                                                if (tableArr[j] == "XMLXDM" || tableArr[j] == "XMAPFS" || tableArr[j] == "SFFNDAPJH" || tableArr[j] == 'JHXZ' || tableArr[j] == 'XMLB' || tableArr[j] == 'PC') {
                                                    inside = "<td>" + $("." + tableArr[j] + " option[value='" + theobj[tableArr[j]] + "']").html() + "</td>";
                                                    break;
                                                } else if (tableArr[j] == 'LXBM' || tableArr[j] == 'LXMC') {
                                                    inside = '<td>' + obj[i]['TABLE_DKJSGM'][tableArr[j]] + '</td>';
                                                    break;
                                                } else {
                                                    inside = "<td>" + theobj[tableArr[j]] + "</td>";
                                                    break;
                                                }
                                            }
                                        }
                                    } else {
                                        if (theobj instanceof Object) {
                                            if (theobj == {} || theobj == '') {
                                                inside = '<td></td>';
                                            } else if (str in theobj) {
                                                if (tableArr[j] == "XMLXDM" || tableArr[j] == "XMAPFS" || tableArr[j] == "SFFNDAPJH" || tableArr[j] == 'JHXZ' || tableArr[j] == 'XMLB' || tableArr[j] == 'PC') {
                                                    inside = "<td>" + $("." + tableArr[j] + " option[value='" + theobj[tableArr[j]] + "']").html() + "</td>";
                                                    break;
                                                } else {
                                                    inside = "<td>" + theobj[tableArr[j]] + "</td>";
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            tdStr += inside;
                        }
                    }
                }
                if (!mFlag) {
                    //正常流程
                    if (parseInt(obj[i]['modified']) == 0) {
                        if (localStorage.acId.indexOf('fomation') == -1 && localStorage.acId != 'undefined') {
                            if (obj[i]['to_division'] == division && obj[i]['to_career'] == career) {
                                //省厅
                                if (localStorage.acId == 'road_trial_third') {
                                    // 审核
                                    if (status == '审核通过审批未接收' || status == '已下达' || status == '审核不通过' || status == '审核退回' || status == '是否确认审核通过审批未接收' || status == '是否确认下达') {
                                        trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                } else if (localStorage.acId == 'road_trial_forth') {
                                    //审批
                                    if (status == '审核通过审批未接收' || status == '审核中') {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else {
                                        trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                } else if (localStorage.acId == 'road_combine') {
                                    // 子项目整合
                                    if (status == '是否确认审核通过审批未接收' || status == '是否确认下达') {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else {
                                        trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                } else {
                                    trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                }
                            } else {
                                var user_right = localStorage.user_right;
                                if (user_right == 'trial_first') {
                                    //初审
                                    (status == '初审未接收' || status == '初审中' || status == '审查退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                } else if (user_right == 'trial_second') {
                                    (status == '审查未接收' || status == '审查中' || status == '审核退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                } else if (user_right == 'trial_third') {
                                    (status == '审核未接收' || status == '审核中' || status == '审批退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                }
                            }
                        } else {
                            if (obj[i]['to_division'] == division && obj[i]['to_career'] == career) {
                                //省厅上报
                                if (obj[i].up_org.indexOf(division) != -1 && obj[i].up_org.indexOf(career) != -1) {
                                    if (status == '财务未确认' || status == '未上报' || status.indexOf('不通过') != -1 || status == '审核未接收') {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else {
                                        status.indexOf('退回') != -1 ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                } else {
                                    if (status == '财务未确认' || status == '未上报') {
                                        trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>"
                                    } else {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>"
                                    }
                                }
                            } else {
                                if (obj[i]['first_trial'] == '' && obj[i]['second_trial'] == '') {
                                    (status == '审核未接收' || status.indexOf('审核退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                } else if (obj[i]['first_trial'] == '' && obj[i]['second_trial'] != '') {
                                    (status == '审查未接收' || status.indexOf('审查退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                } else {
                                    (status == '初审未接收' || status.indexOf('初审退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                }
                            }
                        }
                    } else {
                        trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                    }
                } else {
                    //变更
                    if (parseInt(obj[i]['modified']) == 0 && localStorage.acId.indexOf('change_fomation') != -1 && status == '已下达') {
                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                    } else {
                        if (parseInt(obj[i]['modified']) == 1) {
                            if (localStorage.acId.indexOf('change_fomation') == -1) {
                                if (obj[i]['to_division'] == division && obj[i]['to_career'] == career) {
                                    //省厅
                                    if (localStorage.acId == 'road_change_trial_third') {
                                        // 审核
                                        if (status == '审核通过审批未接收' || status == '已下达' || status == '审核不通过' || status == '审核退回' || status == '是否确认审核通过审批未接收' || status == '是否确认下达') {
                                            trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        } else {
                                            trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        }
                                    } else if (localStorage.acId == 'road_change_trial_forth') {
                                        //审批
                                        if (status == '审核通过审批未接收' || status == '审核中') {
                                            trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        } else {
                                            trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        }
                                    } else {
                                        trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                } else {
                                    var user_right = localStorage.user_right;
                                    if (user_right == 'trial_first') {
                                        //初审
                                        (status == '初审未接收' || status == '初审中' || status == '审查退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else if (user_right == 'trial_second') {
                                        (status == '审查未接收' || status == '审查中' || status == '审核退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else if (user_right == 'trial_third') {
                                        (status == '审核未接收' || status == '审核中' || status == '审批退回') ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                }
                            } else {
                                if (obj[i]['to_division'] == division && obj[i]['to_career'] == career) {
                                    if (obj[i].up_org.indexOf(division) != -1 && obj[i].up_org.indexOf(career) != -1) {
                                        if (status == '财务未确认' || status == '未上报' || status.indexOf('不通过') != -1 || status == '审核未接收' || status == '是否确认下达') {
                                            trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        } else {
                                            status.indexOf('退回') != -1 ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                        }
                                    } else {
                                        if (status == '财务未确认' || status == '未上报') {
                                            trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>"
                                        } else {
                                            trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>"
                                        }
                                    }
                                } else {
                                    if (obj[i]['first_trial'] == '' && obj[i]['second_trial'] == '') {
                                        (status == '审核未接收' || status.indexOf('审核退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else if (obj[i]['first_trial'] == '' && obj[i]['second_trial'] != '') {
                                        (status == '审查未接收' || status.indexOf('审查退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    } else {
                                        (status == '初审未接收' || status.indexOf('初审退回') != -1 || status == '未上报' || status == '财务未确认' || status.indexOf('不通过') != -1) ? trStr += "<tr data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id=\"" + obj[i]['identifier'] + "\"><td><input type='checkbox'></td>" + tdStr + "</tr>";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $('#myTable>tbody').empty().append(trStr);
        if (!$('.data-table').hasClass('data-table1')) $('.data-table').fixTable(4);
        var totalPage = Math.ceil(totalNum / everyNum);  //总页数
        var everyPage = obj.length;   //当前页条数
        $('.inputsTyle').eq(1).val(totalPage);
        $('.inputsTyle').eq(2).val(everyPage);
        $('.inputsTyle').eq(4).val(totalNum);
    },
    getArr: function (className) {
        var theadArr = [];
        var theadDataArr = [];
        var theadName = "";
        var theadDataName = ""
        var tr = "";
        var tr1 = "";
        var tr2 = ""
        var trArr = [];
        var trArr1 = [];
        var trData = '';
        var trData1 = '';
        var trData2 = '';
        var trDataArr = '';
        var trDataArr1 = '';
        var tableClass = className ? className : "#myTable";
        $(tableClass + '>thead>tr').eq(1).find("th").each(function (ele, i) {
            if ($(this).attr("colspan")) {
                for (var i = 0, len = $(this).attr("colspan"); i < len; i++) {
                    tr += $(this).html() + ",";
                    trData += $(this).attr('data-head') + ",";
                }
            } else {
                tr += $(this).html() + ",";
                trData += $(this).attr('data-head') + ",";
            }
        });
        // 获得第三个的tr数组
        $(tableClass + '>thead>tr').eq(2).find("th").each(function (ele, i) {
            tr1 += $(this).html() + ",";
            trData1 += $(this).attr('data-head') + ",";

        });
        trArr = tr.split(',').slice(0, tr.split(',').length - 1);
        trArr1 = tr1.split(',').slice(0, tr1.split(',').length - 1);
        trDataArr = trData.split(',').slice(0, trData.split(',').length - 1);
        trDataArr1 = trData1.split(',').slice(0, trData1.split(',').length - 1);
        // 将几个数组进行替换和叠加
        $(tableClass + '>thead>tr').eq(0).find("th").each(function (ele, i) {
            var that = this;
            theadName += $(this).html() + ',';
            theadDataName += $(this).attr('data-head') + ',';
            if ($(this).attr("colspan")) {
                if ($(tableClass + '>thead>tr').eq(1).find("th").attr("colspan")) {
                    for (var i = 0, len = $(this).attr("colspan"); i < len; i++) {
                        tr2 += $(this).html() + trArr[i] + trArr1[i] + ",";
                        // trData2 += $(this).attr('data-head') + ",";
                        trData2 += trDataArr1[i] + ",";
                    }
                } else {
                    for (var i = 0, len = $(this).attr("colspan"); i < len; i++) {
                        tr2 += $(this).html() + trArr[i] + ",";
                        // trData2 += $(this).attr('data-head') + ",";
                        trData2 += trDataArr[i] + ",";
                    }
                }
                trArr = trArr.slice($(this).attr("colspan"));
                trDataArr = trDataArr.slice($(this).attr("colspan"));
                trArr1 = trArr1.slice($(this).attr("colspan"));
                trDataArr1 = trDataArr1.slice($(this).attr("colspan"));
                tr2 = tr2.slice(0, tr2.length - 1);
                trData2 = trData2.slice(0, trData2.length - 1);
                theadName = theadName.replace($(this).html(), tr2);
                theadDataName = theadDataName.replace($(this).attr('data-head'), trData2);
                tr2 = "";
                trData2 = '';
            }
        });
        theadArr = theadName.split(',').slice(1, theadName.split(',').length - 1);
        theadDataArr = theadDataName.split(',').slice(1, theadDataName.split(',').length - 1);
        // $('.inputsTyle').eq(2).val(numpage);
        $('.inputsTyle').eq(4).val(data.length);
        var returnVal = className ? theadDataArr : theadArr;
        return returnVal;
    },
    pageQuery: function (currentPage, everyNumber) {
        var self = this;
        //当页数发生改变
        if ($('#myTable').length > 0) {
            this.createTr(data, currentPage, everyNumber)
        } else if ($('#bbMakeTable').length > 0) {
            bbMakeTable(data, currentPage, everyNumber);
        } else if ($('#bbUploadTable').length > 0) {
            bbUploadTable(data, currentPage, everyNumber);
        } else if ($('#bbAcceptTable').length > 0) {
            bbAcceptTable(data, currentPage, everyNumber);
        } else if ($('#bbSearchTable').length > 0) {
            bbSearchTable(data, currentPage, everyNumber);
        } else if ($('#userTable').length > 0) {
            userTable(data, currentPage, everyNumber);
        }
        var totallyPage = $('.pageTotally').val();
        $(".inputsTyle").eq(0).off('change').on('change', function () {
            var pageNumber = $(".inputsTyle").eq(0).val();
            if (pageNumber - 0 > 0 && parseInt(pageNumber) <= parseInt(totallyPage)) {
                $(".inputsTyle").eq(0).val(pageNumber);
                getProject(everyNum, pageNumber, $(this).filterSearch());
            } else {
                alert("请输入正确范围内的页码");
            }
        });

        //上一页
        $(".pageUp").off('click').on('click', function () {
            var pageNumber = $(".inputsTyle").eq(0).val();
            if (pageNumber - 0 > 1) {
                pageNumber = parseInt($(".inputsTyle").eq(0).val()) - 1;
                $(".inputsTyle").eq(0).val(pageNumber);
                getProject(everyNum, pageNumber, $(this).filterSearch());
            }
        });

        //下一页
        $(".pageDown").off('click').on('click', function () {
            var pageNumber = $(".inputsTyle").eq(0).val();
            if (pageNumber - 0 + 1 <= parseInt(totallyPage)) {
                pageNumber = parseInt($(".inputsTyle").eq(0).val()) + 1;
                $(".inputsTyle").eq(0).val(pageNumber);
                getProject(everyNum, pageNumber, $(this).filterSearch());
            }
        });

        //第一页
        $(".pageStart").off('click').on('click', function () {
            $(".inputsTyle").eq(0).val(1);
            getProject(everyNum, 1, $(this).filterSearch());
        });

        //最后一页
        $(".pageEnd").off('click').on('click', function () {
            $(".inputsTyle").eq(0).val(totallyPage);
            getProject(everyNum, totallyPage, $(this).filterSearch());
        });
    },
    selectTab: function () {
        var self = this;
        $(".selectTab").on('change', function () {
            if ($("option:selected", this).index() == 1) {
                $('.tableWrap').eq(0).show().siblings('.tableWrap').hide();
                $('.routeConstruct') ? $('.routeConstruct').show() : ""; //是否加入字段校验
            } else if ($("option:selected", this).index() == 2) {
                $('.tableWrap').eq(1).show().siblings('.tableWrap').hide();
                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
            } else if ($("option:selected", this).index() == 3) {
                $('.tableWrap').eq(2).show().siblings('.tableWrap').hide();
                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
            } else if ($("option:selected", this).index() == 4) {
                $('.tableWrap').eq(3).show().siblings('.tableWrap').hide();
                $('.wuliuShow').addClass('none').siblings().removeClass('none');
                $('.sfsShow').addClass('none');
                $('.jzxShow').addClass('none');
                $('.fsrcShow').removeClass('none');
                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
            } else if ($("option:selected", this).index() == 5) {
                $('.tableWrap').eq(3).show().siblings('.tableWrap').hide();
                $('.keyunShow').addClass('none').siblings().removeClass('none');
                $('.sfsShow').removeClass('none');
                $('.jzxShow').removeClass('none');
                $('.fsrcShow').addClass('none');
                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
            } else {
                $('.tableWrap').show();
                $('.routeConstruct').removeClass('none');
            }
        });
        //国省
        $('.selectOption').on('change', function () {
            if ($("option:selected", this).index() == 2) {
                $('.gsShow').removeClass('none');
            } else {
                if (!$('.gsShow').hasClass('none')) {
                    $('.gsShow').addClass('none');
                }
            }
        });
        //是否纳入省计划
        $('.XMAPFS').on('change', function () {
            if ($('option:selected', this).val() != "4" && $('option:selected', this).val() != "") {
                $('.modal-body1:last>.row').eq(0).find('.data-get').prev().addClass('color-red');
                $('.modal-body1:last>.row').eq(1).find('.data-get').prev().addClass('color-red');
            } else {
                $('.modal-body1:last>.row').eq(0).find('.data-get').prev().removeClass('color-red');
                $('.modal-body1:last>.row').eq(1).find('.data-get').prev().removeClass('color-red');
            }
        });
        self.reselect('.select-sel1');
        self.reselect('.select-sel2');
    },
    reselect: function (className) { //路线包含桥梁和路线包含隧道选择
        $('.bridgeWrap1').on('change', className, function () {
            var num = $(className).index($(this)); //当前select的下标值
            if ($("option:selected", this).index() == 1) {
                if (className == '.select-sel1') {
                    $('.containerBri').eq(num).show();
                } else {
                    $('.containerTun').eq(num).show();
                }

            } else {
                if (className == '.select-sel1') {
                    $('.containerBri').eq(num).hide();
                } else {
                    $('.containerTun').eq(num).hide();
                }
            }
        });
    },
    selectChange: function (className, str, inputName, dataCode, hash) {
        var clickEvent = 'click.' + hash;
        $(className).on(clickEvent, function () {
            var addres = str + $("option:selected", this).html();
            inputName.val(addres);
            $(inputName).attr('data-vercode', dataCode);
            $(inputName).attr('data-vername', $("option:selected", this).html());
            $('.treeBox_2').hide();
            $(className).off(clickEvent);
            $('.treeSecLevel .secondLev2').off('click.second');
            $('.treeSecLevel .thirdLev2').off('click.third');
        });
    },
    treeNodeRemove: function (i) {
        $('.secondLev' + i).removeClass('treeActive');
        $('.thirdLev' + i).removeClass('treeActive');
        $('.forthLev' + i).removeClass('treeActive');
        $('.fifthLev' + i).removeClass('treeActive');
        $('.fourthLev2').removeClass('treeActive');
    },
    treeNode1: function (className, i, className1) {
        $('.firstLev' + i).click(function (e) {
            e.stopPropagation();
            $.treeNodeRemove(i);
            $(this).addClass('treeActive');
            if (className.length == 1) {
                if (className.hasClass('industry') || className.hasClass('multiple')) {
                    if (!$(this).next('ul').length) {
                        address = $(this).html();
                        className.val(address);
                    }
                } else if (className.hasClass('xzqh-code')) {
                    addCode = $(this).html().split(' ')[1];
                    className.val(addCode).attr('data-vercode', addCode);
                } else {
                    address = $(this).html().slice(0, 4);
                    addCode = $(this).html().slice(4, $(this).html().length);
                    i == 1 ? className.val(address) : "";
                    i == 1 ? className.attr('data-verCode', addCode.slice(0, addCode.length)) : "";
                }
            }
        });
    },
    treeNode2: function (className, i, className1, input) {
        if (!/^\./.test(className1)) input = className1;
        var that = this;
        $('.treeSecLevel .thirdLev2').off('click');
        $('.treeSecLevel .secondLev' + i).on('click', function (e) {
            e.stopPropagation();
            var address = "";
            var addCode = '';
            $.treeNodeRemove(i);
            $(".firstLev" + i).addClass('treeActive');
            $(this).addClass('treeActive');
            if (className.hasClass('multiple')) {
                if (!$(this).next('ul').length) {
                    address = className.val();
                    var upVal = '';
                    $(className1 + ' .treeActive').each(function (j) {
                        upVal += $(this).html().replace(/\s[\d]+/, "") + '-';
                    });
                    upVal = upVal.substring(0, upVal.length - 1);
                    if (address.indexOf(upVal) == -1) {
                        address = address == '' ? '' : address + ';';
                        address += upVal;
                        className.val(address);
                    }
                }
            } else if (className.hasClass('industry')) {
                if (!$(this).next('ul').length) {
                    $(className1 + ' .treeActive').each(function (j) {
                        address += $(this).html().replace(/\s[\d]+/, "") + '-';
                    });
                    address = address.substring(0, address.length - 1);
                    className.attr('data-code', toDevision(address.split('-')[0]));
                    className.attr('data-career', address.split('-')[1]);
                    className.val(address);
                }
            } else if (className.hasClass('xzqh-code')) {
                addCode = $(this).html().split(' ')[1];
                className.val(addCode).attr('data-vercode', addCode);
            } else {
                $('.treeActive').each(function (j) {
                    address += $(this).html().replace(/\s[\d]+/, "") + '-';
                });
                address = address.substring(0, address.length - 1);
                addCode = toDevision(address);
                address += "/";
                i == 1 ? className.val(address) : that.selectChange(".divikind", address, input, addCode, 1);
                i == 1 ? className.attr('data-verCode', addCode) : "";
            }
        });
    },
    treeNode3: function (className, i, className1, input, multiVal) {
        var that = this;
        if (!/^\./.test(className1)) input = className1;
        $('.treeSecLevel .secondLev' + i).on('click', function (e) {
            e.stopPropagation();
            $.treeNodeRemove(i);
            $(this).addClass('treeActive');
        });
        $('.treeSecLevel .thirdLev' + i).on('click', function (e) {
            e.stopPropagation();
            var address = "";
            var addCode = '';
            $.treeNodeRemove(i);
            $(".firstLev" + i).addClass('treeActive');
            $(this).parent().parent().parent().find(".secondLev" + i).addClass('treeActive');
            $(this).addClass('treeActive');
            if (className.hasClass('multiple')) {
                address = className.val();
                var upVal = '';
                if (!$(this).next('ul').length) {
                    $(className1 + ' .treeActive').each(function (j) {
                        upVal += $(this).html() + '-';
                    });
                    upVal = upVal.substring(0, upVal.length - 1).replace(/(-厅管厅属|-机场|-投资公司)/, '');
                    if (address.indexOf(upVal) == -1) {
                        address = address == '' ? '' : address + ';';
                        address += upVal;
                        className.val(address);
                    }
                }
            } else if (className.hasClass('industry')) {
                if (!$(this).next('ul').length) {
                    $(className1 + ' .treeActive').each(function (j) {
                        address += $(this).html().replace(/\s[\d]+/, '') + '-';
                    });
                    address = address.substring(0, address.length - 1).replace(/(-厅管厅属|-机场|-投资公司)/, '');
                    className.attr('data-code', toDevision(address.split('-')[0]));
                    className.attr('data-career', address.split('-')[1]);
                    className.val(address);
                }
            } else if (className.hasClass('xzqh-code')) {
                addCode = $(this).html().split(' ')[1];
                className.val(addCode).attr('data-vercode', addCode);
            } else {
                $('.treeActive').each(function (j) {
                    address += $(this).html().replace(/\s[\d]+/, '') + '-';
                });
                address = address.substring(0, address.length - 1);
                addCode = toDevision(address);
                address += "/";
                i == 1 ? className.val(address.slice(0, address.length - 1)) : (!$('.thirdLev2.treeActive').length ? '' : that.selectChange(".divikind", address, input, addCode, 0));
                i == 1 ? className.attr('data-verCode', addCode) : "";
            }
        });
    },
    treeNode4: function (className, i, className1, input, multiVal) {
        var that = this;
        if (!/^\./.test(className1)) input = className1;
        $('.treeSecLevel .forthLev' + i).on('click', function (e) {
            e.stopPropagation();
            var address = "";
            var addCode = '';
            $.treeNodeRemove(i);
            $(".firstLev" + i).addClass('treeActive');
            $(this).parent().parent().parent().parent().parent().find('.secondLev' + i).addClass('treeActive');
            $(this).parent().parent().parent().find('.thirdLev' + i).addClass('treeActive');
            $(this).addClass('treeActive');
        });
    },
    treeNode5: function (className, i, className1, input, multiVal) {
        var that = this;
        if (!/^\./.test(className1)) input = className1;
        $('.treeSecLevel .fifthLev' + i).on('click', function (e) {
            e.stopPropagation();
            var address = "",
                addCode = '',
                upVal = '';
            $.treeNodeRemove(i);
            $(".firstLev" + i).addClass('treeActive');
            $(this).parent().parent().parent().parent().parent().parent().parent().find('.secondLev' + i).addClass('treeActive');
            $(this).parent().parent().parent().parent().parent().find('.thirdLev' + i).addClass('treeActive');
            $(this).parent().parent().parent().find('.forthLev' + i).addClass('treeActive');
            $(this).addClass('treeActive');
            if (!$(this).next('ul').length) {
                if (className.hasClass('multiple')) {
                    address = className.val();
                    $(className1 + ' .treeActive').each(function (j) {
                        upVal += $(this).html() + '-';
                    });
                    upVal = upVal.substring(0, upVal.length - 1).replace(/(-地市|(-直属单位|-区县单位))/g, '');
                    var addressArr = upVal.split('-');
                    if (addressArr[addressArr.length - 1].length > 5 && addressArr[addressArr.length - 1].indexOf('交通运输局') != -1) {
                        upVal = upVal.replace(/(交通运输局)/, '-') + '交通运输局';
                    }
                    if (address.indexOf(upVal) == -1) {
                        address = address == '' ? '' : address + ';';
                        address += upVal;
                        className.val(address);
                    }
                } else {
                    $(className1 + ' .treeActive').each(function (j) {
                        address += $(this).html() + '-';
                    });
                    if (!$(this).next('ul').length) {
                        address = address.substring(0, address.length - 1).replace(/(-地市|(-直属单位|-区县单位))/g, '');
                        var addressArr = address.split('-');
                        if (addressArr[addressArr.length - 1].length > 5 && addressArr[addressArr.length - 1].indexOf('交通运输局') != -1) {
                            className.attr('data-code', toDevision(address.replace(/(交通运输局)/, '')));
                            className.attr('data-career', '交通运输局');
                        } else {
                            className.attr('data-code', toDevision(addressArr[0] + '-' + addressArr[1]));
                            className.attr('data-career', addressArr[addressArr.length - 1]);
                        }
                        className.val(address);
                    }
                }
            }
        });
    },
    tree: function () {
        $('#tree').treeview({
            animated: "fast",
            control: "#treecontrol",
            // persist: "cookie",
            // cookieId: "treeview-black"
        });
    },
    division: function (className, className1, iconName) {
        var that = this;
        var multiVal = '';
        var larr = top.location.pathname.split('/'),
            type = larr[larr.length - 1].split('.')[0];
        $(iconName).off('click').on('click', function () {
            if (className1 == '.treeBox_1') $('body').append(treeBox_1);
            if (className1 == '.treeBox_3') $('body').append(treeBox_3);
            if (className1 == '.treeBox_4') $('body').append(treeBox_4);
            $.tree();
            $(className1).show();
            if (iconName == '.divisionIcon4') {
                $('.firstLev3').removeClass('treeActive');
                $.treeNodeRemove(3);
                that.treeNode1($(this).prev(), 3, className1);
                that.treeNode2($(this).prev(), 3, className1);
                that.treeNode3($(this).prev(), 3, className1);
                that.treeNode4($(this).prev(), 3, className1);
                that.treeNode5($(this).prev(), 3, className1);
            } else {
                $('.firstLev1').removeClass('treeActive');
                $.treeNodeRemove(1);
                that.treeNode1($(this).prev(), 1, className1);
                that.treeNode2($(this).prev(), 1, className1);
                that.treeNode3($(this).prev(), 1, className1);
                that.treeNode4($(this).prev(), 1, className1);
                that.treeNode5($(this).prev(), 1, className1);
            }
            $(className1).drag('treeBox_1', className1);
            $(className1).drag('treeBox_3', className1);
            $(className1).drag('treeBox_4', className1);

            $('body').off('click').on('click', '.closeIcon', function () {
                $(className1).hide();
                $('.treeSecLevel').off('click').hide();
                $('.treeSecLevel .secondLev1').off('click');
                $('.treeSecLevel .thirdLev1').off('click');
                if (className1 == '.treeBox_1') $(className1).remove();
                if (className1 == '.treeBox_3') $(className1).remove();
                if (className1 == '.treeBox_4') $(className1).remove();
            });
        });
    },
    newAdd: function (identifier, status, uporg, userName, modified) {
        var larr = top.location.pathname.split('/'),
            type = larr[larr.length - 1].split('.')[0];
        var tableDataArr = [];
        var selectedValue = "";
        var manySele = "";
        var addData = {};
        var add = {};
        if (type == 'lnxm') {
            var projectType = $('[id^=lnxm].active', parent.document).attr('data-type');
            add = {
                "XMID": identifier,
                "project_type": projectType,
                "content": {}
            }
            if (projectType != 'nc') {
                add.content['GS_NDJH_FJXX'] = [];
                add.content['GS_NDJH_TZXX'] = [];
                add.content['T_LXKZD'] = [];
            }
        } else {
            add = {
                "status": "未上报",
                "identifier": identifier,
                "modified": "0",
                "user_name": localStorage.user_name,
                "sub_item": true,
                "item_id": [],
                "content": {
                    "GS_NDJH_FJXX": [],
                    "GS_NDJH_TZXX": [],
                    "reply_xx": [],
                    "T_LXKZD": [],
                    "issued_career": $('.issued-career input').attr('data-code') + $('.issued-career input').attr('data-career')
                }
            };

            if (localStorage.acId == 'road_combine') {
                if ($('#ghxzModal .confirmBtn').eq(0).attr('data-type') == 'addNew' || $('#ghxzModal .confirmBtn').eq(1).attr('data-type') == 'editNew') {
                    add['sub_item'] = true;
                    add['item_id'] = [];
                } else {
                    add['sub_item'] = false;
                    add['item_id'] = [];
                    if ($('.selected-container').length) {
                        $('.selected-container tbody>tr').each(function () {
                            add['item_id'].push($(this).attr('data-id'));
                        })
                    }
                }
            }
            if (status != undefined) {
                add["status"] = status;
            } else if (localStorage.getItem('acId') == 'road_combine') {
                /^(sj)/.test(type) ? add["status"] = '是否确认下达' : add["status"] = '是否确认审核通过审批未接收';
            } else if ($('.tabContainer').hasClass('sjxz') || $('.tabContainer').hasClass('ncContainer') || $('.tabContainer').hasClass('bjContainer')) {
                add["status"] = '财务未确认';
            }
            if (modified != undefined) {
                add["trial_first"] = '';
                add["trial_second"] = '';
                add["third_third"] = '';
                add["trial_forth"] = '';
                add["modified"] = modified;
            }
            if (uporg != undefined) {
                addData.up_org = uporg;
            } else {
                addData.up_org = localStorage.division_code + localStorage.career;
            }
            if (userName != undefined) {
                add['user_name'] = userName;
            }

            // 批复文件
            $('.replyTab>tbody>tr').each(function () {
                var replyData = {};
                replyData.pflx = $(this).find('td').eq(0).find('select').find('option:selected', this).val();
                replyData.pfwh = $(this).find('input').eq(0).val()
                replyData.pfsj = $(this).find('input').eq(1).val();
                replyData.pfjssj = $(this).find('input').eq(2).val();
                if (replyData.pflx && replyData.pfwh && replyData.pfsj && replyData.pfjssj) {
                    add.content.reply_xx.push(replyData);
                }
            });
            add.project_type = type;
            if (localStorage.getItem('item') != undefined) {
                add.project_type = type.replace(/^(sj)/, 'jt');
            } else if (type == 'sy' || type == 'zc') {
                add.project_type = $('.tabContainer').attr('data-type');
            }

            if ($('#ghxzModal .first_trial').val() == '' && $('#ghxzModal .second_trial').val() == '') {
                var value = $("#ghxzModal .third_trial").attr('data-vercode');
                add.to_division = value.substring(0, 6);
                add.to_career = $("#ghxzModal .third_trial").val().split('/')[1];
            } else if ($('#ghxzModal .first_trial').val() == '') {
                add.to_division = $('#ghxzModal .second_trial option:selected').val();
                add.to_career = $('#ghxzModal .second_trial option:selected').attr('data-vername')
            } else {
                add.to_division = $('#ghxzModal .first_trial').attr('data-vercode');
                add.to_career = $('#ghxzModal .first_trial').attr('data-vername');
            }
            //地图
            if (!!sessionStorage.getItem('mapArray')) {
                var map = [],
                    mapArray = sessionStorage.getItem('mapArray').split(';');
                for (var i = 0; i < mapArray.length; i++) {
                    map.push(mapArray[i].split('/'));
                }
                addData.map_local = map;
            }
            add.category = addData.project_kind;
            add.content['JHBZND'] = new Date().getFullYear();
        }
        var tableData = {},
            tableKzd = [];

        // 附件
        $('.file_add>tbody>tr').each(function (i) {
            var fileData = {};
            fileData.FJMC = $(this).find('td').eq(0).html();
            fileData.file_size = $(this).find('td').eq(1).html();
            fileData.FJLX = $(this).find('td').eq(2).find('select').find('option:selected', this).html();
            fileData.FJMS = $(this).find('input').val();
            fileData.up_user = $(this).find('td').eq(4).html();
            fileData.SCTIME = $(this).find('td').eq(5).html();
            // fileData.XMID = $(this).attr('data-id');
            fileData.FJURL = $(this).attr('data-url') + '?' + $(this).attr('data-id');
            if ($(this).find('td').eq(0).html() != "") {
                add.content.GS_NDJH_FJXX.push(fileData);
            }
        });
        $('.sourceTab>tbody>tr').each(function (i) {
            var sourceData = {};
            // $(this).find('td>select').find('option:selected', this);
            sourceData.JHZJLY = $(this).find('td').eq(0).find('select').find('option:selected', this).val();
            sourceData.JHZJSE = $(this).find('input').val();
            sourceData.SFNLS = $(this).find('td').eq(2).find('select').find('option:selected', this).val();
            sourceData.TZLB = $(this).find('td').eq(3).find('select').find('option:selected', this).val();
            if (sourceData.JHZJLY && sourceData.JHZJSE && sourceData.SFNLS && sourceData.TZLB) {
                add.content.GS_NDJH_TZXX.push(sourceData);
            }
        });
        $('.kzd-table').each(function (i) {
            tableKzd = [];
            $(this).find('tr').each(function () {
                tableData = {};
                var wz = $(this).find('td').eq(0).html();
                tableData['JD'] = $(this).find('td').eq(3).html();
                tableData['WD'] = $(this).find('td').eq(4).html();
                tableData['WZBS'] = wz == '起点' ? '1' : (wz == '讫点' ? '2' : '3');
                tableData['SXH'] = $(this).find('td').eq(1).html();
                tableData['SZDMC'] = $(this).find('td').eq(2).html();
                tableData['XMMC'] = $('.XMMC').val();
                tableData['JHWYBM'] = $('.JHWYBM').val();
                tableData['BZ'] = $('.lx-kzd:nth-child(' + parseInt(i + 1) + ')').find('.BZ').val();
                tableData['LXBM'] = $('.lx-kzd:nth-child(' + parseInt(i + 1) + ')').find('.LXBM').val();
                tableData['LXMC'] = $('.lx-kzd:nth-child(' + parseInt(i + 1) + ')').find('.LXMC').val();
                tableKzd.push(tableData);
            });
            add.content.T_LXKZD.push(tableKzd);
        });
        //多表的数据
        if ($('.checkTable').length != 0) {
            $.multipleData('.bodyObj', add, type);
            $.multipleData('.bodyArr', add, type);
        }
        $('.tabContainer > .modal-body:not(.body) .data-get').each(function (i) {
            var className = $(this).attr('data-name');
            if ($('.' + className).hasClass('input')) { //获取input的值
                if (className == "name") {
                    add[className] = $('.' + className).val();
                    addData[className] = $('.' + className).val();
                } else {
                    if ($('.' + className).attr('data-vercode') && $('.' + className).attr('data-vername') && $('.' + className).attr('data-vername') != '1') {
                        addData[className] = $(this).find('.' + className).attr('data-vercode') + $(this).find('.' + className).attr('data-vername');
                    } else if ($('.' + className).attr('data-vercode') && !$('.' + className).attr('data-vername') && $('.' + className).attr('data-vercode') != '1') {
                        addData[className] = $(this).find('.' + className).attr('data-vercode');
                    } else {
                        addData[className] = $(this).find('.' + className).val();
                    }
                }
            } else if ($('.' + className).hasClass('select')) { //获取select的值
                if ($('.' + className).attr('multiple')) { //判断是否为多选
                    for (var i = 0; i < $('.' + className + ' li.selected').length; i++) {
                        manySele += $('.' + className + ' li.selected').eq(i).find('.text').html() + ","
                    }
                    selectedValue = manySele.slice(0, manySele.length - 1);
                    addData[className] = selectedValue;
                } else { //不是多选的处理
                    if (className == "second_trial") {
                        if ($('.' + className + " option:selected").html().indexOf("请选择") != -1) {
                            addData[className] = "";
                        } else {
                            addData[className] = $('.' + className + " option:selected").val() + $('.' + className + " option:selected").html().slice(4);
                        }
                    } else {
                        if ($('.' + className + " option:selected").html().indexOf("请选择") != -1) {
                            addData[className] = '';
                        } else {
                            addData[className] = $('.' + className + " option:selected").html();
                        }
                    }
                }
            } else {
                addData[className] = $('.' + className).val();
            }
        });
        add.content = $.extend({}, add.content, addData);
        return add;
    },
    multipleData: function (tableName, add, type) { //多表的数据
        var objName = "",
            manySele = "",
            selectedValue = "";
        $('.modal-bodylast .data-get').each(function (i, ele) { //获取初审机构等的值
            var className = $(this).attr('data-name');
            if ($('.' + className).hasClass('input')) { //获取input的值
                if ($('.' + className).attr('data-vercode') && $('.' + className).attr('data-vername') && $('.' + className).attr('data-vername') != '1') {
                    add.content[className] = $(this).find('.' + className).attr('data-vercode') + $(this).find('.' + className).attr('data-vername');
                } else if ($('.' + className).attr('data-vercode') && !$('.' + className).attr('data-vername')) {
                    add.content[className] = $(this).find('.' + className).attr('data-vercode');
                } else {
                    add.content[className] = $(this).find('.' + className).val();
                }
            } else {
                if (className == "second_trial") {
                    if ($('.' + className + " option:selected").html().indexOf("请选择") != -1) {
                        add.content[className] = "";
                    } else {
                        add.content[className] = $(this).find('.' + className + " option:selected").val() + $('.' + className + " option:selected").html().slice(4);
                    }
                } else {
                    add.content[className] = $(this).find('.' + className + " option:selected").val();
                }
            }
        });
        $(tableName).each(function (j, ele) {
            if (!$(this).hasClass('none') || $(this)[0].style.display != 'none') {
                objName = $(this).attr('data-body');
                var tableData = {};
                var tableDataArr = [];
                var emptyBool = false;
                if (objName == 'TABLE_JMDXX') {
                    var valid = $('.jmdInput:checked').val();
                    if (!!valid) {
                        tableData['enable'] = true;
                        emptyBool = true;
                    } else {
                        tableData['enable'] = false;
                        emptyBool = true;
                    }
                }
                if (objName == 'TABLE_XMJBXX' || objName == 'GS_NDJH_XMJBXX' || objName == 'TABLE_LWGSGC' || objName == 'SJ_JBXX') {
                    tableData['JHBZND'] = new Date().getFullYear();
                }
                if (objName == 'GS_NDJH_XMJBXX') {
                    tableData['XZQH'] = '330000000000';
                }
                $(this).find('.data-get').each(function (j) {
                    var className = $(this).attr('data-name');
                    //行政区划名称
                    if (className == 'XZQHMC') {
                        tableData['XZQH'] = getxzqhCode('XZQHMC')[0];
                        tableData['XZQHMC'] = getxzqhCode('XZQHMC')[1];
                    } else if (className == 'XZQH') {
                        var value = $(this).find('.' + className).attr('data-vercode');
                        tableData['XZQH'] = value == '1' ? '' : value;
                    } else if (className == 'SXM') {
                        tableData['SXM'] = $('.MSXM').val() + $('.ZSXM').val();
                    } else if ($(this).find('.' + className).hasClass('input') || $(this).find('.' + className).hasClass('textarea')) { //获取input的值
                        if (className == "XMMC" && type != 'lnxm') {
                            add[className] = $(this).find('.' + className).val();
                            $(this).find('.' + className).val() ? emptyBool = true : "";
                        }
                        tableData[className] = $(this).find('.' + className).val();
                        $(this).find('.' + className).val() ? emptyBool = true : "";
                    } else if ($(this).find('.' + className).hasClass('select')) { //获取select的值
                        if ($(this).find('.' + className).attr('multiple')) { //判断是否为多选
                            for (var i = 0; i < $(this).find('.' + className).find(' li.selected').length; i++) {
                                if ($(this).find('.' + className).find(' li.selected').eq(i).find('.text').html().indexOf("请选择") != -1) {
                                    $(this).find('.' + className).find(' li.selected').eq(i).find('.text').html("");
                                }
                                manySele += $(this).find('.' + className).find(' li.selected').eq(i).find('.text').html() + ","
                            }
                            selectedValue = manySele.slice(0, manySele.length - 1);
                            tableData[className] = selectedValue;
                            selectedValue ? emptyBool = true : "";
                        } else { //不是多选的处理
                            if (className == 'XMLXDM' || className == 'JSXZDM' || className == 'SFFNDAPJH' || className == 'JDGZ' || className == 'LDJSDJ' || className == 'LDLMLX' || className == 'ZJBZDM' || className == 'AKJF' || className == 'SJHZ' || className == 'JMDLX' || className == 'TDZK' || className == 'XXBLXDM') {
                                var hy = $(this).find('.' + className).attr('data-hy');
                                if (hy != undefined) tableData[hy] = $(this).find('.' + className + ' option:selected').html();
                            }
                            if (className == 'ZJ') {
                                $(this).find('.' + className).each(function () {
                                    if (!$(this).hasClass('none')) tableData[className] = $(this).val();
                                    $(this).find('.' + className + " option:selected").val() ? emptyBool = true : "";
                                })
                            } else {
                                tableData[className] = $(this).find('.' + className + " option:selected").val();
                                $(this).find('.' + className + " option:selected").val() ? emptyBool = true : "";
                            }
                        }
                    } else {
                        tableData[className] = $(this).find('.' + className).val();
                        $(this).find('.' + className).val() ? emptyBool = true : "";
                    }
                });
                if (objName == 'SJ_JYJH') {
                    tableData['SBCXJ'] = ($('.ZYTZ').val() - 0) + ($('.JTTZ').val() - 0) + ($('.QTZJ').val() - 0) + ($('.STXJ').val() - 0);
                }
                if (tableName == '.bodyObj') {
                    emptyBool ? add.content[objName] = tableData : add.content[objName] = {};
                } else {
                    if (add.content[objName]) {
                        emptyBool ? add.content[objName].push(tableData) : "";
                    } else {
                        tableDataArr.push(tableData);
                        emptyBool ? add.content[objName] = tableDataArr : add.content[objName] = [];
                    }
                }
            }
        });
    },
    cityChange: function () {
        $('.xzqh-province').on('change', function () {
            //省
            var province = $(this)[0].value,
                cityHtml = '',
                that = $(this);
            if (province == '330000') {
                cityHtml = '<option value=""></option>' +
                    '<option value="330100">杭州市</option>' +
                    '<option value="330200">宁波市</option>' +
                    '<option value="330300">温州市</option>' +
                    '<option value="330400">嘉兴市</option>' +
                    '<option value="330500">湖州市</option>' +
                    '<option value="330600">绍兴市</option>' +
                    '<option value="330700">金华市</option>' +
                    '<option value="330800">衢州市</option>' +
                    '<option value="330900">舟山市</option>' +
                    '<option value="331000">台州市</option>' +
                    '<option value="331100">丽水市</option>';
            } else {
                cityHtml = '<option value=""></option>';
                that.next().next().empty().append(cityHtml);
            }
            that.next().empty().append(cityHtml);
        });
        //市
        $('.xzqh-city').on('change', function () {
            var city = $(this)[0].value,
                areaHtml = '',
                that = $(this);
            if (city == '') {
                areaHtml = '';
            } else {
                for (var i in devisionc) {
                    if (i.substring(0, 4) == city.substring(0, 4) && i != city) {
                        var value = devisionc[i].substring(8, devisionc[i].length);
                        areaHtml += '<option value="' + i + '">' + value + '</option>';
                    }
                }
            }
            areaHtml = '<option value=""></option>' + areaHtml;
            that.next().empty().append(areaHtml);
        });
    },
    newAddSubmit: function () {
        this.fileActive();
        // 上传
        $('.xzfile').on('change', function () {
            $.fileUp('.xzform', '.file_add');
        });
        $('.csfile').on('change', function () {
            $.fileUp('.csform', '.file_cs');
        });
        $('.scfile').on('change', function () {
            $.fileUp('.scform', '.file_sc');
        });
        $('.shfile').on('change', function () {
            $.fileUp('.shform', '.file_sh');
        });
        //删除
        $('.op-delete').off('click').on('click', function () {
            var index = $(this).parent().attr('data-index');
            var type = $(this).attr('data-type');
            if (type == 'lnxm') {
                delData(index, type);
            } else {
                if ($('#bbMakeTable tbody tr:nth-child(' + index + ') .status').html() != '未确认') {
                    alertMs('只能删除未确认的报表');
                    return false;
                }
                delData(index);
            }
        });
        //新增报表
        $('.add_report').off('click').on('click', function () {
            $('#ghxzModal input').val('');
            $('#ghxzModal input.BBWJ').attr('data-id', '');
            $('#ghxzModal input.BBWJ').attr('data-url', '');
            $('#ghxzModal input.ZBJG').val('浙江省-交通运输厅');
            tableMake();
            $('.makeBtn').off('click').on('click', function () {
                addReport();
            });
            $('.addLnxm').off('click').on('click', function () {
                addLnxm();
            })
        });
        //报表制作确认
        $('.op-sure').on('click', function () {
            var index = $(this).parent().attr('data-index');
            var currentName = devisionc[localStorage.getItem('division_code')] + '-' + localStorage.getItem('career');
            if (currentName != data[index - 1]["ZBJG"]) {
                alertMs('你没有权限进行确认');
                return false;
            }
            bbStatus('确认', index);
        });
        //上报任务报表接收
        $('.bb_upload_accept').off('click').on('click', function () {
            var that = $(this);
            bbAccept('接收报表', that);
        });
        //上报报表
        $('.bbup').off('click').on('click', function () {
            $('#jhInfoModal input').val('');
            $('#jhInfoModal input.SHJG').val('浙江省-交通运输厅');
            $('#jhInfoModal input.SBWJ').attr('data-id', '');
            $('#jhInfoModal input.SBWJ').attr('data-url', '');
            if ($(this).parent().parent().hasClass('forbidden')) {
                alertMs('你没有权限进行上报');
                return false;
            }
            var that = $(this);
            var value = $(this).parent().parent().find('.uploadorg').html();
            $('.SHJG').val(value);
            var bbIndex = $(this).attr('data-index');
            //上报报表
            $('.editBtn').off('click').on('click', function () {
                upChange('上报', that, bbIndex);
            })
        });
        //制表查看
        $('.make-modal').off('click').on('click', function () {
            makeSee($(this));
        })
        //删除文件
        $('.wj_delete').off('click').on('click', function () {
            if ($(this).parent().parent().hasClass('forbidden')) {
                alertMs('你没有权限进行删除');
                return false;
            }
            var bbIndex = $(this).attr('data-bb');
            var wjIndex = $(this).attr('data-index');
            var that = $(this);
            upChange('删除', that, bbIndex, wjIndex);
        });
        // 接收文件
        $('.wj_accept').off('click').on('click', function () {
            var that = $(this);
            bbAccept('接收文件', that);
        });
        //审核文件
        $('.wj_sh').off('click').on('click', function () {
            if ($(this).parent().parent().hasClass('forbidden') || $(this).parents('tr').find('.wjstatus').html() == '审核不通过') {
                alertMs('你没有权限进行审核');
                return false;
            }
            var that = $(this);
            var bbIndex = $(this).attr('data-bb');
            var wjIndex = $(this).attr('data-index');
            //确认
            $('.editBtn').off('click').on('click', function () {
                upChange('审核', that, bbIndex, wjIndex);
            })
        });
        // 上报文件
        $('.wj_sup').off('click').on('click', function () {
            var that = $(this);
            bbAccept('上报文件', that);
        })
        if ($('.XMLXDM').hasClass('nclwXm')) {
            $('.XMLXDM').on('change', function () {
                var value = $('.XMLXDM option:selected').html();
                var jsHtml = '';
                if (value == '村道危桥改造项目') {
                    jsHtml = '<option value=""></option>' +
                        '<option value="4">拆除重建</option>' +
                        '<option value="5">加固改造</option>';
                } else {
                    jsHtml = '<option value=""></option>' +
                        '<option value="1">新建</option>' +
                        '<option value="2">改建</option>' +
                        '<option value="3">新改建</option>' +
                        '<option value="4">拆除重建</option>' +
                        '<option value="5">加固改造</option>';
                }
                $('.JSXZDM').empty().append(jsHtml);
            });
        }
        if ($('.kzd_del').length) $.kzdOperate();
        // 新增控制点
        $('.kzd_btn span:first-child').off('click').on('click', function () {
            if (kzdPlineArr.length) {
                for (var a in kzdPlineArr) {
                    maplet.removeOverlay(kzdPlineArr[a]);
                }
            }
            var btnArr = [];
            $('.kzd .notNull').each(function () {
                var dataType = $(this).attr('data-type'),
                    dataText = $(this).attr('data-text');
                if (dataType == 'select') {
                    var value = $(this).find('option:selected').val();
                    if (value == '') {
                        $(this).addClass('checkErr');
                        alertMs(dataText + '不能为空');
                        return false;
                    } else {
                        $(this).removeClass('checkErr');
                        btnArr.push(value);
                    }
                } else if (dataType == 'input') {
                    var value = $(this).val();
                    if (value == '') {
                        $(this).addClass('checkErr');
                        alertMs(dataText + '不能为空');
                        return false;
                    } else {
                        $(this).removeClass('checkErr');
                        btnArr.push(value);
                    }
                }
            });
            if (btnArr.length == 4) $.addKzd($(this));
            $.kzdOperate();
        });
        // 确认控制点
        $('.kzd_btn span:nth-child(2)').off('click').on('click', function () {
            if (kzdPlineArr.length) {
                for (var a in kzdPlineArr) {
                    maplet.removeOverlay(kzdPlineArr[a]);
                }
            }
            mapPolyline();
            $.kzdOperate();
        });
        //查询子项目
        $('.sure-item').off('click').on('click', function () {
            $('#ghitemSelect').show().addClass('modalActive').siblings().removeClass('modalActive');
            $('#ghitemSelectModal').show().siblings().hide();
            $('.item-btn span:first-child').off('click').on('click', function () {
                var XMMC = $('.item-XMMC').val(),
                    JHWYBM = $('.item-JHWYBM').val();
                if (XMMC != '' || JHWYBM != '') {
                    $('.item-container tbody>tr').each(function () {
                        if (XMMC == '') {
                            if (JHWYBM != $(this).find('td').eq(2).html()) {
                                $(this).addClass('unsearchItem');
                            }
                        } else {
                            if ($(this).find('td').eq(1).html().indexOf(XMMC) == -1) {
                                $(this).addClass('unsearchItem');
                            } else {
                                if (JHWYBM != '' && JHWYBM != $(this).find('td').eq(2).html()) {
                                    $(this).addClass('unsearchItem');
                                }
                            }
                        }
                    });
                    $('tr.unsearchItem').hide();
                }
            })
            $('.item-btn span').eq(1).off('click').on('click', function () {
                $('.item-container tbody>tr').removeClass('unsearchItem').show();
                $('.item-XMMC,.item-JHWYBM').val('');
            })
        });
        // 新增子项目
        $('.add-new-item').off('click').on('click', function () {
            $('#ghitemAdd').show().addClass('modalActive').siblings().removeClass('modalActive');
            $('#ghxzModal').show().siblings().hide();
            $('#ghxzModal').show();
            $('.xzBtn').show();
            $('.xgBtn').hide();
            $('.confirmBtn').eq(0).attr('data-type', 'addNew');
            $('.issued-career').removeClass('none');
            //清空已填数据
            $('#ghxzModal').find('input:not(".jmdInput,.jbxzqh,.XMTBRDWDM,.XMTBRDWMC,.JHNF")').val('');
            $('#ghxzModal').find('textarea').val('');
            $('#ghxzModal .third_trial').val('浙江省/交通运输厅');
            $('#ghxzModal').find('select:not(".jqqx")').val('');
        })
        // 子母项目确认
        $('.confirmItem').off('click').on('click', function () {
            upload('确认', 'item')
        });
        //自动生成项目编码
        $('.XMLB-select').on('change', function () {
            var value = '2017' + $('.XMLB option:selected').val() + $('.MSXM').val() + $('.ZSXM').val();
            $('.XMBM').val(value);
        });
        $('.MSXM').on('change', function () {
            var value = $(this).val();
            if (value.length != 3) {
                alertMs('顺序码的母码为3位');
            } else {
                $('.XMBM').val('2017' + $('.XMLB option:selected').val() + value + $('.ZSXM').val());
            }
        });
        $('.ZSXM').on('change', function () {
            var value = $(this).val();
            if (value.length != 1) {
                alertMs('顺序码的子码为1位');
            } else {
                $('.XMBM').val('2017' + $('.XMLB option:selected').val() + $('.MSXM').val() + value);
            }
        });

        $('.xmfm-btn').off('click').on('click', function () {
            $.post('/api/gh_project_info?code=' + $('.XMFM').val(), {}, function (res) {
                getCoding(JSON.parse(res));
            });
        });

        $('.cd-bridge').on('change', function () {
            var quality1 = '<option value=""></option>' +
                '<option value="1">新建</option>' +
                '<option value="2">改建</option>' +
                '<option value="3">新改建</option>';
            var quality2 = '<option value=""></option>' +
                '<option value="4">拆除重建</option>' +
                '<option value="5">加固改造</option>';
            var qualitySelect = $(this).parents('.cd-bridge-parent').next().find('select');
            switch ($(this).val()) {
                case '40':
                    // 桥梁建设
                    qualitySelect.empty().append(quality1);
                    break;
                case '41':
                    // 村道危桥改造
                    qualitySelect.empty().append(quality2);
                    break;
                default:
                    break;
            }
        });
        areaInvalid();
        $('.save-image').off('click').on('click', function () {
            toImg('myMap', 'image');
            // maplet.setMode('snapshot');
        })
        //提交按钮
        $('.confirmBtn').eq(0).off('click').on('click', function () {
            var dataType = $(this).attr('data-type');
            $('.tabContainer').hasClass('sjContainer') ? sjCheck('xz') : ($('.tabContainer').hasClass('ncContainer') ? ncCheck('xz') : $.contentCheck('xz'));
            if (!$('#ghxzModal').find('.data-get').children().hasClass('checkErr') && !$('#ghxzModal').find('.zjin').hasClass('checkErr')) {
                if (localStorage.getItem('acId') == 'road_combine' && $('.selected-container tbody tr').length == 0 && dataType != 'addNew') {
                    alertMs('请选择关联的子项目');
                } else {
                    $(this).attr('disabled', true);
                    var data = JSON.stringify($.newAdd(guid()));
                    $.ajax({
                        type: 'post',
                        url: '/api/add_project?user_name=' + localStorage.user_name,
                        data: data,
                        success: function (result) {
                            addItemArr.push(result);
                            $('.tabContainer modal-body .data-get').children('input').val('');
                            if (dataType == 'addNew') {
                                alertMs('新增子项目成功', 1, function () {
                                    $('#ghitem').addClass('modalActive').siblings().removeClass('modalActive');
                                    $('#ghitemModal').show().siblings().hide();
                                    $('#ghitemAdd').hide();
                                    $('html', window.top.document).animate({ scrollTop: 0 }, 1000);
                                    var larr = top.location.pathname.split('/'),
                                        type = larr[larr.length - 1].split('.')[0];
                                    $.addItem('.selected-container', type);
                                })
                            } else {
                                $('#myModalgh').modal('hide');
                                location.reload();
                            }
                        },
                        error: function (error) {
                            console.log(error);
                        }
                    });
                }
            }
        });
    },
    kzdOperate: function () {
        // 删除控制点
        $('.kzd_del').on('click', function () {
            if (kzdPlineArr.length) {
                for (var a in kzdPlineArr) {
                    maplet.removeOverlay(kzdPlineArr[a]);
                }
            }
            $(this).parents('tr').remove();
        });
        $('.kzd_edit').off('click').on('click', function () {
            if ($(this).hasClass('kzd_sure')) {
                // 确认修改控制点
                $.kzdSure($(this));
            } else {
                // 修改控制点
                if (kzdPlineArr.length) {
                    for (var a in kzdPlineArr) {
                        maplet.removeOverlay(kzdPlineArr[a]);
                    }
                }
                $.kzdEdit($(this));
                $(this).html('确认').addClass('kzd_sure');
            }
        })
    },
    pageJump: function () {
        if ($('.mianbaoxie a').html()) {
            var pageMark = $('.mianbaoxie a').html();
            $(window).unload(function () {
                sessionStorage.setItem('mark', pageMark);
            });
        }
        $('.mianbaoxie a').on('click', function () {
            localStorage.removeItem('item_name');
            localStorage.removeItem('item');
        });
    },
    versionSee: function () {
        var versionData = [],
            logData = [],
            divStr = "",
            cloneHtml = '';
        $('.versionView').on('click', function () {
            versionData = [];
            logData = [];
            divStr = "";
            var cloneTr = '';
            var Active = $('#myTable tbody>tr>td:first-child input[type="checkbox"]:checked');
            switch (Active.length) {
                case 0:
                    alertMs('请勾选一条数据');
                    return false;
                    break;
                case 1:
                    cloneHtml = Active.parents('tr');
                    cloneTr = cloneHtml.clone();
                    var guid = cloneHtml.attr('data-id');
                    $.ajax({
                        type: "get",
                        url: "/api/get_version?project_id=" + guid,
                        dataType: "json",
                        success: function (result) {
                            versionData = result;
                            for (var i = versionData.length; i > 0; i--) {
                                divStr += '<div class="col-sm-1 version">版本' + i + '</div>';
                            }
                            divStr = '<div class="col-sm-1 version versionActive">当前版本</div>' + divStr;
                            $('.new-version').empty().append(divStr);
                        },
                        error: function () {

                        }
                    });
                    $.ajax({
                        type: "get",
                        url: "/api/get_log?project_id=" + guid,
                        dataType: "json",
                        success: function (result) {
                            var add = result;
                            var dataName = $.getArr('#myTable1');
                            var logTr = '';
                            $(".log-table>tbody").empty();
                            $.each(add, function (name, val) {
                                logTr += "<tr><td>" + val[0] + "</td><td>" + val[1] + "</td><td>" + val[2] + "</td></tr>";
                            });
                            $(".log-table>tbody").append(logTr);
                        },
                        error: function () {

                        }
                    });
                    break;
                default:
                    alertMs('只能勾选一条数据进行版本查看');
                    return false;
                    break;
            }
            cloneTr.children().eq(0).remove();
            cloneTr.removeClass('active');
            $('#myTable1>tbody').empty().append(cloneTr);

        });
        $('.versionBox').off('click').on('click', '.version', function () {
            $(this).addClass('versionActive').siblings().removeClass('versionActive');
            var add = versionData[$(this).html().replace(/[^\d]/g, '') - 1];
            $.versionEvent(add, $(this).html(), cloneHtml);
        });

        $('.verChange .prev').off('click').on('click', function (data) {
            if ($('.versionBox').find('.versionActive').prev().length != 0) {
                $('.versionBox').find('.versionActive').prev().addClass('versionActive').siblings().removeClass('versionActive');
            }
            var add = versionData[$('.versionBox .versionActive').html().replace(/[^\d]/g, '') - 1];
            $.versionEvent(add, $('.versionBox .versionActive').html(), cloneHtml);
        });
        $('.verChange .next').off('click').on('click', function () {
            if ($('.versionBox').find('.versionActive').next(".version").length != 0) {
                $('.versionBox').find('.versionActive').next().addClass('versionActive').siblings().removeClass('versionActive');
            }
            var add = versionData[$('.versionBox .versionActive').html().replace(/[^\d]/g, '') - 1];
            $.versionEvent(add, $('.version').index($(this)), cloneHtml);
        });
    },
    versionEvent: function (add, index, cloneHtml) {
        var dataName = getThead()[1];
        if (add) {
            var bodyHtml = '',
                content = add.content,
                tdStr = '';
            for (var i = 0; i < dataName.length; i++) {
                if (dataName[i] == 'status') {
                    bodyHtml += '<td>' + cloneHtml.find('td').eq(1).html() + '</td>';
                } else if (dataName[i] == 'up_org' || dataName[i] == 'first_trial' || dataName[i] == 'second_trial' || dataName[i] == 'third_trial') {
                    var value = content[dataName[i]];
                    if (value != '') {
                        bodyHtml += ('<td>' + devisionc[value.substring(0, 6)] + '/' + value.substring(6, value.length) + '</td>');
                    } else {
                        bodyHtml += '<td></td>';
                    }
                } else {
                    for (var j in content) {
                        if (content[j] instanceof Object) {
                            if (content[j].hasOwnProperty(dataName[i])) {
                                if (dataName[i] == "XMLXDM" || dataName[i] == "XMAPFS" || dataName[i] == "SFFNDAPJH" || dataName[i] == 'JHXZ' || dataName[i] == 'XMLB' || dataName[i] == 'PC') {
                                    tdStr = '<td>' + $("." + dataName[i] + " option[value='" + content[j][dataName[i]] + "']").html() + '</td>';
                                    break;
                                } else {
                                    tdStr = '<td>' + content[j][dataName[i]] + '</td>';
                                }
                            }
                        } else {
                            if (dataName[i] == "XMLXDM" || dataName[i] == "XMAPFS" || dataName[i] == "SFFNDAPJH" || dataName[i] == 'JHXZ' || dataName[i] == 'XMLB' || dataName[i] == 'PC') {
                                tdStr = '<td>' + $("." + dataName[i] + " option[value='" + content[j] + "']").html() + '</td>';
                            } else {
                                if (dataName[i] == j) tdStr = '<td>' + content[j] + '</td>';
                            }
                        }
                    }
                    bodyHtml += tdStr;
                }
            }
            bodyHtml = '<tr>' + bodyHtml + '</tr>';
            $('#myTable1>tbody').empty().append(bodyHtml);
        }
        if (index == "当前版本") {
            var cloneTr = cloneHtml.clone();
            cloneTr.children().eq(0).remove();
            cloneTr.removeClass('active');
            $('#myTable1>tbody>tr').remove();
            $('#myTable1>tbody').empty().append(cloneTr);
        }
    },
    contentCheck: function (buttonType, projectId) {
        var planCode = [],
            xzCode = [], //行政区划代码
            proplanCode = [], //建议计划规划编码
            ghplanCode = [],
            xzqhCode = [],  //行政区划代码
            qhCode = ['01', '02', '03'],
            ywCode = ['1', '2', '3', '4', '5'],
            xmCode1 = ['01', '02', '03', '05', '08', '09', '10', '11', '19'],
            xmCode2 = ['01', '02', '03', '04', '19'],
            xmCode3 = ['01', '02', '03', '05', '06', '07', '08', '19'],
            xmCode4 = ['01', '02', '03', '19'],
            xmCode5 = ['06', '07', '19'];
        //下级单位代码
        var dwCode = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'H', 'G', 'J', 'S', 'X', 't'];
        // var cityCode=['00','01','02','03','04','05','06','07','08','09','10','11'];
        var notEmpty = 0;
        //去除之前的checkErr
        $('.data-get').children().removeClass('checkErr');

        for (var i in devisionc) {
            xzCode.push(i);
        }
        for (var i = 0; i < data.length; i++) {
            if (!!data[i]['GS_NDJH_XMJBXX']) {
                if (buttonType == 'xg') {
                    if (data[i]['identifier'] != projectId) {
                        planCode.push(data[i]['GS_NDJH_XMJBXX'].JHWYBM);
                        proplanCode.push(data[i]['GS_NDJH_XMJBXX'].GHBM.slice(5, 10));
                    }
                } else {
                    planCode.push(data[i]['GS_NDJH_XMJBXX'].JHWYBM);
                    proplanCode.push(data[i]['GS_NDJH_XMJBXX'].GHBM.slice(5, 10));
                }
            }
            if (!!data[i]['project_plan_code']) {
                if (buttonType == 'xg') {
                    data[i]['identifier'] != projectId && ghplanCode.push(data[i]['project_plan_code'].slice(5, 10));
                } else {
                    ghplanCode.push(data[i]['project_plan_code'].slice(5, 10));
                }
            }
        }
        // 字段校验
        var dataGet1 = [];
        var dataGet = [];
        if ($('.data-type').attr('data-type') == 'gljy') {
            $('#ghxzModal').find('.checkTable').each(function () {
                if ($(this).css('display') != 'none') {
                    dataGet1.push($(this).find('.data-get'));
                }
            });
            for (var i = 0; i < dataGet1.length; i++) {
                for (var j = 0; j < dataGet1[i].length; j++)
                    dataGet.push(dataGet1[i][j]);
            }
        } else {
            $('#ghxzModal').find('.data-get').each(function () {
                dataGet.push($(this));
            });
        }
        var count = 0;
        $.each(dataGet, function (i) {
            count++;
            if ($(this).prev().hasClass('color-red') && $(this).attr('data-name') != 'SFFXZQHTX' && !$(this).find('.' + $(this).attr('data-name')).hasClass('none')) {
                if ($(this).children().hasClass('select')) {
                    if ($(this).children().find('option:selected').val() == "") {
                        $(this).children().addClass('checkErr');
                        alertMs($(this).prev().html().replace(":", "") + "不能为空", 1, function () {
                            scrollAnimate();
                        });
                        return false;
                    } else {
                        // 建成后路段技术等级代码
                        if ($(this).attr('data-name') == 'LDJSDJ' && $('.LDJSDJ_XZ option:selected').val() != '') {
                            if ($('.LDJSDJ option:selected').val() > $('.LDJSDJ_XZ option:selected').val()) {
                                $(this).children().addClass('checkErr');
                                alertMs("建成后路段技术等级代码不小于现状路段技术等级代码", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        } else {
                            $(this).children().removeClass('checkErr');
                        }

                    }
                } else {
                    if ($(this).children().val() == "") {
                        $(this).children().addClass('checkErr');
                        alertMs($(this).prev().html().replace(":", "") + "不能为空", function () {
                            scrollAnimate();
                        });
                        return false;
                    } else {
                        //安排年份
                        if ($('.JHWYBM').val() != "") {
                            if ($(this).attr('data-name') == "JHNF") {
                                if ($(this).children().val() != $('.JHWYBM').val().slice(0, 4)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("计划安排年份应与项目计划编码的1-4位相同", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        }
                        //项目填报人单位代码
                        if ($(this).attr('data-name') == "XMTBRDWDM") {
                            if ($(this).children().val().length != 9) {
                                $(this).children().addClass('checkErr');
                                alertMs("项目填报人单位代码应为9位", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                var checkCode = $(this).children().val().slice(0, 2) +
                                    $(this).children().val().slice(3, 5) + $(this).children().val().slice(6, 8);
                                if ($.inArray(checkCode, xzCode) == '-1') {
                                    $(this).children().addClass('checkErr');
                                    alertMs("项目填报人单位代码出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                                if ($.inArray($(this).children().val().slice(2, 3), dwCode) == '-1') {
                                    $(this).children().addClass('checkErr');
                                    alertMs("项目填报人单位代码第3位出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                                if ($(this).children().val().slice(3, 5) != "00") {
                                    if ($(this).children().val().slice(5, 6) != $(this).children().val().slice(2, 3)) {
                                        $(this).children().addClass('checkErr');
                                        alertMs("项目填报人单位代码第6位出错", function () {
                                            scrollAnimate();
                                        });
                                        return false;
                                    } else {
                                        $(this).children().removeClass('checkErr');
                                    }
                                } else {
                                    if ($(this).children().val().slice(5, 6) != 0) {
                                        $(this).children().addClass('checkErr');
                                        alertMs("项目填报人单位代码第6位出错", function () {
                                            scrollAnimate();
                                        });
                                        return false;
                                    } else {
                                        $(this).children().removeClass('checkErr');
                                    }
                                }
                                if ($(this).children().val().slice(6, 8) != "00") {
                                    if ($(this).children().val().slice(8, 9) != $(this).children().val().slice(2, 3)) {
                                        $(this).children().addClass('checkErr');
                                        alertMs("项目填报人单位代码第9位出错", function () {
                                            scrollAnimate();
                                        });
                                        return false;
                                    } else {
                                        $(this).children().removeClass('checkErr');
                                    }
                                } else {
                                    if ($(this).children().val().slice(8, 9) != 0) {
                                        $(this).children().addClass('checkErr');
                                        alertMs("项目填报人单位代码第9位出错", function () {
                                            scrollAnimate();
                                        });
                                        return false;
                                    } else {
                                        $(this).children().removeClass('checkErr');
                                    }
                                }
                            }
                        }
                        //匹配带单位的应为整数或精确小于4的小数
                        if ($(this).prev().html().match(/\(*\)/)) {
                            if ($(this).children().val().match(/^[0-9]+.?[0-9]*$/g) || $(this).children().val() == "") {
                                $(this).children().removeClass('checkErr');
                                if (!$(this).children().val() == "" && !$(this).children().val().match(/^\d+(\.\d{1,3})?$/g)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs($(this).prev().html() + '最多可精确到小数点后3位', function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            } else {
                                $(this).children().addClass('checkErr');
                                alertMs($(this).prev().html() + "内容为非负数", function () {
                                    scrollAnimate();
                                });
                                return false;
                            }
                        }
                        //止点桩号大于起点桩号
                        if ($(this).attr('data-name') == "ZDZH") {
                            if (($(this).children().val() - 0) < ($('.LXQDZH').val() - 0)) {
                                $(this).children().addClass('checkErr');
                                alertMs("止点桩号应大于起点桩号", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        //中央投资小于总投资
                        if ($(this).attr('data-name') == "ZYTZ") {
                            if (($(this).children().val() - 0) > ($('.ZTZ').val() - 0)) {
                                $(this).children().addClass('checkErr');
                                alertMs("中央投资应小于等于总投资", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else if (($('.ZYTZ').val() - 0) > ($('.ZTZXD').val() - 0) && $('.ZTZXD').val() != '') {
                                $(this).children().addClass('checkErr');
                                alertMs("中央投资不能大于总投资下达值", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        //总投资>=年度建议计划投资+至上年累计完成投资
                        if ($(this).attr('data-name') == "ZTZ") {
                            if ($('.SFFNDAPJH option:selected').val() == "2") {
                                if ($(this).children().val() != $('.NDJYJHZE').val()) {
                                    $('.NDJYJHZE').addClass('checkErr');
                                    alertMs("总投资=年度建议计划投资", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $('.NDJYJHZE').removeClass('checkErr');
                                }
                            } else { //有问题
                                if (($(this).children().val() - 0) < (($('.NDJYJHZE').val() - 0) + ($('.SNDLJWCTZ').val() - 0))) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("总投资>=年度建议计划投资+至上年累计完成投资", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        }
                        //中央投资>=年度建议投资中央投资+至上年度累计完成中央投资
                        if ($(this).attr('data-name') == "ZYTZ") {
                            if ($('.SFFNDAPJH option:selected').val() == "2") {
                                if ($(this).children().val() != $('.NDJHZYTZ').val()) {
                                    $('.NDJHZYTZ').addClass('checkErr');
                                    alertMs("中央投资=年度建议投资中央投资", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $('.NDJHZYTZ').removeClass('checkErr');
                                }
                            } else { //有问题
                                if (($(this).children().val() - 0) < (($('.NDJHZYTZ').val() - 0) + ($('.SNDLJWCZYTZ').val() - 0))) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("中央投资>=年度建议投资中央投资+至上年度累计完成中央投资", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        }
                        //开工年与完工年的检验
                        if ($(this).attr('data-name') == "JSWGN") {
                            if ($('.SFFNDAPJH option:selected').val() == "1") {
                                if (($(this).children().val() - 0) <= ($('.JSKGN').val() - 0)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("完工年应大于开工年", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            } else if ($('.SFFNDAPJH option:selected').val() == "2") {
                                if ($(this).children().val() != $('.JSKGN').val()) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("开工年应等于完工年", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        }
                        //项目规划编号
                        if ($(this).attr('data-name') == "GHBM" || $(this).attr('data-name') == 'project_plan_code') {
                            var name = $(this).attr('data-name');
                            if (!$('.' + name).val().match(/\d{10}/g)) {
                                $(this).children().addClass('checkErr');
                                alertMs("项目规划编号必须为10位数字", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else if ($.inArray($('.' + name).val().slice(0, 2), qhCode) == -1) {
                                $(this).children().addClass('checkErr');
                                alertMs("项目规划编号1-2有误", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else if ($.inArray($('.' + name).val().slice(2, 3), ywCode) == -1) {
                                $(this).children().addClass('checkErr');
                                alertMs("项目规划编号3有误", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else if ($.inArray($('.' + name).val().slice(2, 3), ywCode) == -1) {
                                switch ($('.' + name).val().slice(2, 3)) {
                                    case "1":
                                        if ($.inArray($('.' + name).val().slice(3, 5), xmCode1) == -1) {
                                            $(this).children().addClass('checkErr');
                                            alertMs("项目规划编号4-5有误", function () {
                                                scrollAnimate();
                                            });
                                            return false;
                                        }
                                        break;
                                    case "2":
                                        if ($.inArray($('.' + name).val().slice(3, 5), xmCode2) == -1) {
                                            $(this).children().addClass('checkErr');
                                            alertMs("项目规划编号4-5有误", function () {
                                                scrollAnimate();
                                            });
                                            return false;
                                        }
                                        break;
                                    case "3":
                                        if ($.inArray($('.' + name).val().slice(3, 5), xmCode3) == -1) {
                                            $(this).children().addClass('checkErr');
                                            alertMs("项目规划编号4-5有误", function () {
                                                scrollAnimate();
                                            });
                                            return false;
                                        }
                                        break;
                                    case "4":
                                        if ($.inArray($('.' + name).val().slice(3, 5), xmCode4) == -1) {
                                            $(this).children().addClass('checkErr');
                                            alertMs("项目规划编号4-5有误", function () {
                                                scrollAnimate();
                                            });
                                            return false;
                                        }
                                        break;
                                    case "5":
                                        if ($.inArray($('.' + name).val().slice(3, 5), xmCode5) == -1) {
                                            $(this).children().addClass('checkErr');
                                            alertMs("项目规划编号4-5有误", function () {
                                                scrollAnimate();
                                            });
                                            return false;
                                        }
                                        break;
                                }
                            } else if ($.inArray($('.' + name).val().slice(5, 10), proplanCode) != -1 && name == 'GHBM') {
                                $(this).children().addClass('checkErr');
                                alertMs("此项目规划编号序列号已存在", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else if ($.inArray($('.' + name).val().slice(5, 10), ghplanCode) != -1 && name == 'project_plan_code') {
                                $(this).children().addClass('checkErr');
                                alertMs("此项目规划编号序列号已存在", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        //计划建设里程
                        if ($(this).attr('data-name') == 'JHJSLC') {
                            var JSZLC = parseFloat($('.JSZLC').val()),
                                JHJSLC = parseFloat($('.JHJSLC').val());
                            if (Math.abs(JHJSLC - JSZLC) >= 1) {
                                $(this).children().addClass('checkErr');
                                alertMs("计划建设里程与建设总里程误差不能超过1米", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        //桥梁全长
                        if ($(this).attr('data-name') == 'QLCD') {
                            var QLCD = parseFloat($('.QLCD').val()),
                                DLQLCD = parseFloat($('.DLQLCD').val());
                            if (Math.abs(DLQLCD - QLCD) >= 1) {
                                $(this).children().addClass('checkErr');
                                alertMs("桥梁全长与独立桥梁长度误差不能超过1米", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        // 隧道长度
                        if ($(this).attr('data-name') == 'SDCD') {
                            var SDCD = parseFloat($('.SDCD').val()),
                                DLSDCD = parseFloat($('.DLSDCD').val());
                            if (Math.abs(DLSDCD - SDCD) >= 1) {
                                $(this).children().addClass('checkErr');
                                alertMs("隧道长度与独立隧道长度误差不能超过1米", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                        $(this).children().removeClass('checkErr');
                    }
                }
            } else {
                if ($(this).children().val() != '') {
                    //项目计划编码input
                    if ($(this).attr('data-name') == 'JHWYBM') {
                        var xzqh = '';
                        $('.XZQH').each(function () {
                            if ($(this).val() != '') {
                                xzqh = $(this).val().substr(0, 6);
                            }
                        })
                        if ($(this).children().val().length != 13) {
                            $(this).children().addClass('checkErr');
                            alertMs($(this).prev().html().replace(":", "") + "应为13位", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else if (xzqh != $(this).children().val().substr(4, 6)) {
                            $(this).children().addClass('checkErr');
                            alertMs("此项目计划编码的第4位-第10位应与建设规模表所在的行政区划相同", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else if ($.inArray($(this).children().val(), planCode) != "-1") {
                            $(this).children().addClass('checkErr');
                            alertMs("此项目计划编码后三位顺序码已存在", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    }
                    //匹配带单位的应为整数或精确小于4的小数input
                    if ($(this).prev().html().match(/\(*\)/)) {
                        if ($(this).children().val().match(/^[0-9]+.?[0-9]*$/g) || $(this).children().val() == "") {
                            $(this).children().removeClass('checkErr');
                            if (!$(this).children().val() == "" && !$(this).children().val().match(/^\d+(\.\d{1,3})?$/g)) {
                                $(this).children().addClass('checkErr');
                                alertMs($(this).prev().html() + '最多可精确到小数点后3位', function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                                // check2 = true;` 
                            }
                        } else {
                            $(this).children().addClass('checkErr');
                            alertMs($(this).prev().html() + "内容为非负数", function () {
                                scrollAnimate();
                            });
                            return false;
                        }
                    }
                    //设计行车速度input
                    if ($(this).attr('data-name') == "SJXCSD") {
                        if (($(this).children().val().replace(/[^\d]/g, '') - 0) > 120) {
                            $(this).children().addClass('checkErr');
                            alertMs("设计行车速度不能大于>120km/h", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    }
                    //至上年度累计完成中央投资小于至上年累计完成投资
                    if ($(this).attr('data-name') == "SNDLJWCZYTZ") {
                        if ($('.SFFNDAPJH option:selected').val() == "2") {
                            if ($(this).children().val() == "0" || $(this).children().val() == "") {
                                $(this).children().removeClass('checkErr');
                            } else {
                                $(this).children().addClass('checkErr');
                                alertMs("至上年度累计完成中央投资应为0或者不填", function () {
                                    scrollAnimate();
                                });
                                return false;
                            }
                        } else {
                            if (($(this).children().val() - 0) > ($('.SNDLJWCTZ').val() - 0)) {
                                $(this).children().addClass('checkErr');
                                alertMs("至上年度累计完成中央投资应小于至上年累计完成投资", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                        }
                    }
                    //至上年累计完成投资
                    if ($(this).attr('data-name') == "SNDLJWCTZ") {
                        if ($('.SFFNDAPJH option:selected').val() == "2") {
                            if ($(this).children().val() == "0" || $(this).children().val() == "") {
                                $(this).children().removeClass('checkErr');
                            } else {
                                $(this).children().addClass('checkErr');
                                alertMs("至上年度累计完成中央投资应为0或者不填", function () {
                                    scrollAnimate();
                                })
                                return false;
                            }
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    }
                    //下级单位代码
                    if ($(this).attr('data-name') == "XJDWDM") {
                        if ($(this).children().val().length != 9) {
                            $(this).children().addClass('checkErr');
                            alertMs("下级单位代码应为9位", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else {
                            var checkCode = $(this).children().val().slice(0, 2) +
                                $(this).children().val().slice(3, 5) + $(this).children().val().slice(6, 8);
                            if ($.inArray(checkCode, xzCode) == '-1') {
                                $(this).children().addClass('checkErr');
                                alertMs("下级单位代码出错", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                            if ($.inArray($(this).children().val().slice(2, 3), dwCode) == '-1') {
                                $(this).children().addClass('checkErr');
                                alertMs("下级单位代码第3位出错", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $(this).children().removeClass('checkErr');
                            }
                            if ($(this).children().val().slice(3, 5) != "00") {
                                if ($(this).children().val().slice(5, 6) != $(this).children().val().slice(2, 3)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("下级单位代码第6位出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            } else {
                                if ($(this).children().val().slice(5, 6) != 0) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("下级单位代码第6位出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                            if ($(this).children().val().slice(6, 8) != "00") {
                                if ($(this).children().val().slice(8, 9) != $(this).children().val().slice(2, 3)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("下级单位代码第9位出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            } else {
                                if ($(this).children().val().slice(8, 9) != 0) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("下级单位代码第9位出错", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        }
                    }
                    //建设总里程
                    if ($(this).attr('data-name') == 'JSZLC') {
                        var total = 0,
                            JSZLC = $('.JSZLC').val();
                        $('.licheng .data-get').each(function () {
                            var className = $(this).attr('data-name');
                            if (className != 'JSZLC' && className != 'ZXLC' && className != 'DLQLCD') {
                                total += parseFloat($('.' + className).val());
                            }
                        });
                        if ((total - 0) != (JSZLC - 0)) {
                            $(this).children().addClass('checkErr');
                            alertMs("建设总里程 = 高速里程 + 一级里程 + 二级里程 + 三级里程 + 四级里程", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    }
                    //至上年度累计完成中央投资
                    if ($(this).attr('data-name') == 'SNDLJWCZYTZ') {
                        if (parseFloat($('.SNDLJWCZYTZ').val()) > 0) {
                            if ($('.XMAPFS option:selected').html() != '中央续安排') {
                                $('.XMAPFS').addClass('checkErr');
                                alertMs("至上年底累计完成中央投资大于0时，项目安排方式必须是“中央续安排项目”", function () {
                                    scrollAnimate();
                                });
                                return false;
                            } else {
                                $('.XMAPFS').removeClass('checkErr');
                            }
                        }
                    }

                    //行政区划(水运)
                    if ($(this).attr('data-name') == 'XZQH') {
                        var JHWYBM = $('.JHWYBM').val();
                        if (JHWYBM != '') {
                            if (!$(this).children().hasClass('jbxzqh')) {
                                if ($(this).children().val().substring(0, 6) != JHWYBM.substring(4, 10)) {
                                    $(this).children().addClass('checkErr');
                                    alertMs("行政区划代码前六位应与项目计划编码4-6位相等", function () {
                                        scrollAnimate();
                                    });
                                    return false;
                                } else {
                                    $(this).children().removeClass('checkErr');
                                }
                            }
                        } else {
                            if (!$(this).children().hasClass('jbxzqh')) {
                                var value = $(this).children().val();
                                if (xzqhCode.length == 0) {
                                    xzqhCode.push(value);
                                    $('.XZQH').removeClass('checkErr');
                                } else {
                                    if ($.inArray(value, xzqhCode) == -1) {
                                        $(this).children().addClass('checkErr');
                                        alertMs("除基本信息表,其他所有的行政区划代码均应相同", function () {
                                            scrollAnimate();
                                        });
                                        return false;
                                    } else {
                                        $(this).children().removeClass('checkErr');
                                    }
                                }
                            }
                        }
                    }
                }
                // 治理类型
                if ($(this).attr('data-name') == 'ZLLX') {
                    if ($('.XMLXDM option:selected').val() == '10') {
                        if ($('.ZLLX option:selected').val() == '') {
                            $(this).children().addClass('checkErr');
                            alertMs("项目类型为航道整治时治理类型不能为空", function () {
                                scrollAnimate();
                            });
                            return false;
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    }
                }
            }
        });
        if (count == dataGet.length) {
            if ($('#ghxzModal').hasClass('sy-modal')) {
                //建设规模文本描述
                var bool = false;
                var that = '';
                $('.JSGMMX').each(function () {
                    if ($(this).val() != '') {
                        bool = true;
                        that = $(this);
                    }
                });
                if (!bool) {
                    $('.JSGMMX').addClass('checkErr');
                    alertMs('建设规模文本描述必须填写一项', function () {
                        scrollAnimate();
                    });
                    return false;
                } else {
                    $('.JSGMMX').removeClass('checkErr');
                    var water = that.attr('data-xzqh');
                    var xzqh = $('.' + water + ' option:selected').val();
                    if (xzqh == '') {
                        $('.' + water).addClass('checkErr');
                        alertMs('行政区划代码不能为空', function () {
                            scrollAnimate();
                        });
                        return false;
                    } else {
                        $('.' + water).removeClass('checkErr');
                    }
                }
            }
            if ($('.sourceTab').length) {
                $('.sourceTab tbody>tr').each(function () {
                    var JHZJLY = $(this).find('td').eq(0).find('select option:selected').val(),
                        JHZJSE = $(this).find('td').eq(1).find('input').val(),
                        SFNLS = $(this).find('td').eq(2).find('select option:selected').val(),
                        TZLB = $(this).find('td').eq(3).find('select option:selected').val();
                    if (JHZJLY == '' && JHZJSE == '' && SFNLS == '' && TZLB == '') {
                        $(this).find('td').eq(0).find('select').addClass('checkErr');
                        alertMs('资金来源必须填一项');
                        return false;
                    }
                    //投资来源代码 
                    if (JHZJLY == '') {
                        $(this).find('td').eq(0).find('select').addClass('checkErr');
                        alertMs("资金来源代码不能为空");
                        return false;
                    } else {
                        $(this).find('td').eq(0).find('select').removeClass('checkErr');
                    }
                    //投资额
                    if (JHZJSE == '') {
                        $(this).find('td').eq(1).find('input').addClass('checkErr');
                        alertMs("投资额不能为空");
                        return false;
                    } else {
                        $(this).find('td').eq(1).find('input').removeClass('checkErr');
                    }
                    //投资类别
                    if (TZLB == '') {
                        $(this).find('td').eq(3).find('select').addClass('checkErr');
                        alertMs("投资类别不能为空");
                        return false;
                    } else {
                        $(this).find('td').eq(3).find('select').removeClass('checkErr');
                    }
                })
            }
            if (localStorage.getItem('acId') == 'road_combine' && $('#ghxzModal .confirmBtn').eq(0).attr('data-type') != 'addNew' && $('#ghxzModal .confirmBtn').eq(1).attr('data-type') != 'editNew') itemCheck();
        }

    },
    fileActive: function () {
        $('.file_add>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
        $('.file_cs>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
        $('.file_sc>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
        $('.file_sh>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
        $('.sourceTab>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
        $('.replyTab>tbody').off('click').on('click', 'tr', function () {
            $(this).addClass('active').siblings().removeClass('active');
        });
    },
    fileUp: function (formName, tableName) {
        $('#barTop', parent.document).css({
            "opacity": '1',
            "width": '20%'
        });
        var upTime = new Date();
        m = upTime.getMonth() + 1;
        var fileTime = upTime.getFullYear() + "-" + m + "-" + upTime.getDate() + " " + upTime.getHours() + ":" + upTime.getMinutes() + ":" + upTime.getSeconds();
        var fileTr = "";
        var fileData = new FormData($(formName)[0]);
        // $(formName).ajaxSubmit({
        //     type: "post",
        //     url: "/api/up_file?user_name=" + localStorage.user_name,
        //     processData : false,
        //     contentType : false ,
        //     xhr: function () {
        //         var xhr = $.ajaxSettings.xhr();
        //         if (onprogress && xhr.upload) {
        //             xhr.upload.addEventListener("progress", onprogress, false);
        //             return xhr;
        //         }
        //     },
        //     success: function(result) {
        //         setTimeout(function(){
        //             $('#son',parent.document).css({"opacity":'0',"transition":"0.3s"});
        //         },500);
        //         var fileSize = parseInt(result[1] / 1024) + "KB";
        //         if (fileSize > 1024) {
        //             fileSize = parseInt(fileSize / 1024) + "M";
        //         }
        //         fileTr = "<tr data-id=" + result[3] + " data-url=/api/" + result[0] + ">" + "<td>" + result[0] + "</td><td>" + fileSize + "</td><td class='fileType'>" + "<select><option value=''>" + "-请选择-</option>" + "<option>公可相关</option>" + "<option>初设相关</option>" + "<option>其他</option>" + "</select>" + "</td>" +
        //             "<td><input type='text' class='fileInp'></td>" + "<td>" + localStorage.user_name + "</td>" + "<td>" + fileTime + "</td>" + "</tr>";
        //         if ($(tableName + '>tbody>tr').length == 0) {
        //             $(tableName + '>tbody').append(fileTr);
        //         } else {
        //             if ($(tableName + '>tbody>tr').find('td').eq(0).html() == "") {
        //                 $(tableName + '>tbody>tr').remove();
        //                 $(tableName + '>tbody').append(fileTr);
        //             } else {
        //                 $(tableName + '>tbody>tr:last').after(fileTr);
        //             }
        //         }
        //     },
        //     error: function(error) {
        //         console.log(error);
        //     }
        // });
        $.ajax({
            type: "post",
            url: "/api/up_file?user_name=" + localStorage.user_name,
            data: fileData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                $('#barTop', parent.document).css({
                    "width": '50%'
                });
            },
            success: function (result) {
                $('#barTop', parent.document).css({
                    "width": '100%'
                });
                setTimeout(function () {
                    $('#barTop', parent.document).css({
                        "opacity": '0'
                    });
                }, 700);
                setTimeout(function () {
                    $('#barTop', parent.document).css({
                        "width": '0'
                    });
                }, 1000);
                var fileSize = parseInt(result[1] / 1024) + "KB";
                if (fileSize > 1024) {
                    fileSize = parseInt(fileSize / 1024) + "M";
                }
                fileTr = "<tr data-id=" + result[3] + " data-url=/api/" + result[0] + ">" + "<td>" + result[0] + "</td><td>" + fileSize + "</td><td class='fileType'>" + "<select><option value=''>-请选择-</option><option value='1'>公可相关</option><option value='2'>初设相关</option><option value='3'>其他</option><option value='4'>地图相关文件</option></select></td>" +
                    "<td><input type='text' class='fileInp'></td>" + "<td>" + localStorage.name + "</td>" + "<td>" + fileTime + "</td>" + "</tr>";
                if ($(tableName + '>tbody>tr').length == 0) {
                    $(tableName + '>tbody').append(fileTr);
                } else {
                    if ($(tableName + '>tbody>tr').find('td').eq(0).html() == "") {
                        $(tableName + '>tbody>tr').remove();
                        $(tableName + '>tbody').append(fileTr);
                    } else {
                        $(tableName + '>tbody>tr:last').after(fileTr);
                    }
                }
                if ($('.tabContainer').hasClass('sjContainer')) {
                    $('.BBWJ,.SBWJ').attr('data-id', result[3]);
                    $('.BBWJ,.SBWJ').attr('data-url', '/api/' + result[0]);
                }
            },
            error: function (error) {
                console.log(error);
            }
        });
    },
    fileDel: function (tableName) {
        if ($(tableName + '>tbody>tr.active').length != 0) {
            var fileId = $(tableName + '>tbody>tr.active').attr('data-id');
            $.ajax({
                type: "get",
                url: "/api/del_file?file_id=" + fileId,
                success: function (result) {
                    $(tableName + '>tbody>tr.active').remove();
                },
                error: function () {

                }
            });
        }
    },
    fileDownLoad: function (tableName, that) {
        var fileUrl = '';
        var fileId = '';
        if (!!that) {
            fileUrl = that.attr('data-url');
            fileId = that.attr('data-id');
        } else if ($(tableName + '>tbody>tr.active').length != 0) {
            fileUrl = $(tableName + '>tbody>tr.active').attr('data-url');
            fileId = $(tableName + '>tbody>tr.active').attr('data-id');
        }
        loadStr = "<a href=" + fileUrl + "?file_id=" + fileId + " class='downLoad'><div class=\"aaa\"></div></a>";
        $('body').append(loadStr);
        $('.aaa').trigger('click');
        $('.downLoad').remove();
    },
    capitalSoure: function () { //资金来源新增
        $('.soureAdd').off('click').on('click', function () {
            var tab = $(this).attr('data-type') == 'reply' ? 'replyTab' : 'sourceTab';
            if ($('.' + tab + '>tbody>tr:first').length) {
                $('.' + tab + '>tbody>tr:last').after($('.' + tab + '>tbody>tr:first').clone());
                $('.' + tab + '>tbody>tr:last').find('input').val("");
                $('.' + tab + '>tbody>tr:last').find('select').val("");
                $('.' + tab + '>tbody>tr:last').find('select').removeClass('checkErr');
            } else {
                var tabHtml = '';
                if (tab == 'reply') {
                    tabHtml = '<tr><td><select style="width:100%; height:100%; border:1px solid #fff" class="zjin">' +
                        '<option value="">--请选择--</option>' +
                        '<option value="工可批复文号">工可批复文号</option>' +
                        '<option value="初设批复文号">初设批复文号</option>' +
                        '<option value="承诺函文号">承诺函文号</option>' +
                        '<option value="其他">其他</option>' +
                        '</select></td>' +
                        '<td><input type="text" style="width:100%; height:100%; border:1px solid #fff"></td>' +
                        '<td><input type="text" style="width:100%; height:100%; border:1px solid #fff"></td>' +
                        '<td><input type="text" style="width:100%; height:100%; border:1px solid #fff"></td></tr>';
                } else {
                    tabHtml = '<tr><td><select style="width:100%; height:100%; border:1px solid #fff" class="zjin">' +
                        '<option value="">--请选择--</option>' +
                        '<option value="01">车购税</option>' +
                        '<option value="02">中央国债</option>' +
                        '<option value="03">地方自筹</option>' +
                        '<option value="04">国内贷款</option>' +
                        '<option value="05">利用外资</option>' +
                        '<option value="06">港建费</option>' +
                        '<option value="07">预算内</option>' +
                        '<option value="09">其他</option></select></td>' +
                        '<td><input type="text" style="width:100%; height:100%; border:1px solid #fff" class="zjin"></td>' +
                        '<td><select style="width:100%; height:100%; border:1px solid #fff" class="zjin">' +
                        '<option value="">--请选择--</option>' +
                        '<option value="1">是</option>' +
                        '<option value="2">否</option></select></td>' +
                        '<td><select style="width:100%; height:100%; border:1px solid #fff" class="zjin">' +
                        '<option value="">--请选择--</option>' +
                        '<option value="98">本批</option>' +
                        '<option value="99">本年</option></select></td></tr>';
                }
                $('.' + tab + '>tbody').append(tabHtml);
            }
            $('.datetimepicker').datetimepicker({
                format: 'yyyy-mm-dd',
                autoclose: true,
                todayBtn: true,
                language: 'zh-CN',
                minView: '2'
            });
            $('body').find('.endDate').on('change', function () {
                var start = $(this).parent().prev().find('input').val(),
                    end = $(this).val();
                if (Date.parse(end.replace(/\-/g, "/")) > Date.parse(start.replace(/\-/g, "/"))) {
                    alert('批件接收时间不能大于批复时间');
                    $(this).val('');
                }
            });
        });
    },
    soureDel: function () { //资金来源的删除
        $('.soureDel').off('click').on('click', function () {
            var tab = $(this).attr('data-type') == 'reply' ? 'replyTab' : 'sourceTab';
            if ($('.' + tab + '>tbody>tr.active').length != 0) {
                if ($('.' + tab + '>tbody>tr').length == 1) {
                    $('.' + tab + '>tbody>tr').find('select').val("");
                    $('.' + tab + '>tbody>tr').find('input').val("");
                } else {
                    $('.' + tab + '>tbody>tr.active').remove();
                }
            }
        });
    },
    firstTrial: function (inputName, iconName) { //初审是否能填写
        // $.tree();
        var userDefinde = localStorage.division_code;
        var provinceArr = ['交通运输厅', '公路局', '港航局', '运管局', '机场局'];
        if (userDefinde == '330000' && $.inArray(localStorage.career, provinceArr) != -1) {
            $(iconName).addClass('disable');
            $(inputName).attr("disabled", true);
        } else {
            $(iconName).removeClass("readonly", "readonly");
            $(inputName).removeAttr("disabled");
        }
    },
    contentWri: function () {
        //自动生成字段
        var unitCode = {
            "交通运输厅": '1',
            "交通运输局": '1',
            "运输厅": '1',
            "公路局": '2',
            "运管局": '7',
            "港航局": '8',
            "港务(航)管理局": '8'
        }
        if (localStorage.career == "公路局") {
            var proName = devisionc[localStorage.division_code] + "公路管理局";
        } else {
            var proName = devisionc[localStorage.division_code] + localStorage.career;
        }
        $('.XMTBRDWMC').val(proName);
        var markCode = unitCode[localStorage.career];
        var proCode = "";
        if (localStorage.division_code.slice(2, 4) != '00') {
            if (localStorage.division_code.slice(4, 6) != '00') {
                proCode = localStorage.division_code.slice(0, 2) + markCode + localStorage.division_code.slice(2, 4) + markCode + localStorage.division_code.slice(4, 6) + markCode;
            } else {
                proCode = localStorage.division_code.slice(0, 2) + markCode + localStorage.division_code.slice(2, 4) + markCode + '000';
            }
        } else {
            proCode = localStorage.division_code.slice(0, 2) + markCode + "000000"
        }
        !!markCode && $('.XMTBRDWDM').val(proCode);
    },
    tableAdd: function (iconName, tableName, tableWrap) {
        var tableNum = 0;
        $(iconName).off('click').on('click', function () {
            tableNum++;
            $(tableName + ':last').after($(tableName + ':first').clone(true));
            //值克隆一个briContainer和tunContainer
            $(tableName + ':last').find('.briContainer').eq(0).siblings('.briContainer').remove();
            $(tableName + ':last').find('.tunContainer').eq(0).siblings('.tunContainer').remove();
            $(tableName + ':last').find('.routeConstruct').show();
            $(tableName + ':last').find('input').val("");
            $(tableWrap + '>h5:last').after($(tableWrap + '>h5:first').clone());
            $(tableWrap + '>h5:last').html($(tableWrap + '>h5').html() + tableNum);
            $(tableWrap + '>h5:last').addClass('h5Active').siblings().removeClass('h5Active');
            $(tableName + ':last').find('h5').eq(0).html($(tableWrap + '>h5').html() + tableNum);
            $(tableName + ':last').find('textarea').val("");
            $(tableName + ':last').find('select>option:selected').val("");
            $(tableName + ':last').slideDown().siblings(tableName).slideUp();
            if ($('.containerBri').length != 0) {
                $('.containerBri:last').hide();
                $('.containerTun:last').hide();
            }
            $('.kzd-table:last tbody').empty();
        });
    },
    tableShow: function (wrapName, tableName) {
        $(wrapName + '>h5').eq(0).addClass('h5Active');
        $(wrapName).off('click').on('click', 'h5', function () {
            if (!$(this).parent().hasClass('row')) {
                $(this).addClass('h5Active').siblings('h5').removeClass('h5Active');
                $(tableName).eq($(this).index()).slideDown().siblings(tableName).slideUp();
            }
        });
    },
    tablesonAdd: function () { //整理
        var briNum = 0;
        var tunNum = 0;
        $('.bridgeBox').off('click').on('click', '.tablesonAdd1', function () {
            if ($(this).parent().parent().find('.briContainer:last').find('h5').eq(0).html().replace(/[^\d]/g, "") == "") {
                briNum = 1;
            } else {
                briNum = parseInt($(this).parent().parent().find('.briContainer:last').find('h5').eq(0).html().replace(/[^\d]/g, "")) + 1;
            }
            $(this).parent().parent().find('.briContainer:last').after($('.briContainer:first').clone(true));
            $(this).parent().parent().find('.briContainer:last').find('h5').eq(0).html($(this).parent().parent().find('.briContainer:last').find('h5').eq(0).html() + briNum);
            $(this).parent().parent().find('.briContainer:last').find('input').val("");
            $(this).parent().parent().find('.briContainer:last').find('textarea').val("");
            $(this).parent().parent().find('.briContainer:last').find('select>option:selected').val("");
        });
        $('.bridgeBox').on('click', '.tablesonAdd2', function () {
            if ($(this).parent().parent().find('.tunContainer:last').find('h5').eq(0).html().replace(/[^\d]/g, "") == "") {
                tunNum = 1;
            } else {
                tunNum = parseInt($(this).parent().parent().find('.tunContainer:last').find('h5').eq(0).html().replace(/[^\d]/g, "")) + 1;
            }
            $(this).parent().parent().find('.tunContainer:last').after($('.tunContainer:first').clone(true));
            $(this).parent().parent().find('.tunContainer:last').find('h5').eq(0).html($(this).parent().parent().find('.tunContainer:last').find('h5').eq(0).html() + tunNum);
            $(this).parent().parent().find('.tunContainer:last').find('input').val("");
            $(this).parent().parent().find('.tunContainer:last').find('textarea').val("");
            $(this).parent().parent().find('.tunContainer:last').find('select>option:selected').val("");
        });
    },
    tableDel: function (tableName, iconName, wrapName) {
        $(tableName).on('click', iconName, function () {
            if ($(iconName).index($(this)) == 0) {
                $(this).parent().find('input').val('');
                $(this).parent().find('textarea').val('');
                $(this).parent().find('select>option:selected').val(" ");
            } else {
                $(this).parent().remove();
                wrapName ? $(wrapName + '>h5.h5Active').remove() : "";
                wrapName ? $(wrapName + '>h5').eq($(iconName).index($(this))).addClass('h5Active').siblings().removeClass('h5Active') : "";
                $(tableName).eq($(iconName).index($(this))).slideDown();
            }
        });
    },
    tableEvent: function () {
        $.tableAdd('.tableAdd1', '.bridgeBox', '.bridgeWrap1');
        $.tableAdd('.tableAdd2', '.DLbridgeBox', '.bridgeWrap2');
        $.tableAdd('.tableAdd3', '.DLtunnelBox', '.bridgeWrap3');
        $.tableAdd('.tableAdd4', '.KYSNBox', '.bridgeWrap4');
        $.tableShow('.bridgeWrap1', '.bridgeBox');
        $.tableShow('.bridgeWrap2', '.DLbridgeBox');
        $.tableShow('.bridgeWrap3', '.DLtunnelBox');
        $.tableShow('.bridgeWrap4', '.KYSNBox');
        $.tablesonAdd();
        $.tableDel('.bridgeBox', '.tableDel1', '.bridgeWrap1');
        $.tableDel('.bridgeWrap1', '.tableDel2');
        $.tableDel('.bridgeWrap1', '.tableDel3');
        $.tableDel('.DLbridgeBox', '.tableDel4', '.bridgeWrap2');
        $.tableDel('.DLtunnelBox', '.tableDel5', '.bridgeWrap3');
        $.tableDel('.KYSNBox', '.tableDel6', '.bridgeWrap4');
    },
    getAlready: function (locaType) {
        //农村公路
        if ((/^(nc)/.test(locaType) && locaType != 'nctj' && locaType != 'nclw') || locaType == 'gljy' || locaType == 'syjy' || locaType == 'zcxt') {
            $.post('/api/get_project?project_type=tl;gs;gsd;wngl;sy_1;sy_2;sy_3;zc_1;zc_2;jc&status=' + encodeURI('已下达'), {}, function (all) {
                all = all['list'];
                var names = [],
                    fiveContent = {},
                    types = [];
                for (var i = 0; i < all.length; i++) {
                    var content = all[i].content;
                    var fiveContent = {
                        'names': content['name'],  //项目名称
                        'ghCodes': content['project_plan_code'],  //项目规划编码
                        'gkCodes': '',  //工可批复文号
                        'csCodes': '',  //初设批复文号
                        'crhCodes': '',  //承诺函文号
                        'startYears': content['construction_start_year'], //开工年
                        'endYears': content['construction_end_year'],  //完工年
                        'xmfm': content['XMFM'],  //项目赋码
                        'identifier': all[i]['identifier']
                    }
                    names.push(content['name']);
                    switch (all[i]['project_type']) {
                        case 'tl':
                            types.push('铁路规划');
                            break;
                        case 'gs':
                            types.push('公路规划-高速公路');
                            break;
                        case 'gsd':
                            types.push('公路规划-国省道');
                            break;
                        case 'wngl':
                            types.push('农村公路');
                            break;
                        case 'sy_1':
                            types.push('水运规划-沿海港口项目');
                            break;
                        case 'sy_2':
                            types.push('水运规划-内河水运建设项目');
                            break;
                        case 'sy_3':
                            types.push('水运规划-陆岛码头建设项目');
                            break;
                        case 'zc_1':
                            types.push('公路站场规划-客运站场建设项目');
                            break;
                        case 'zc_2':
                            types.push('公路站场规划-物流园区建设项目');
                            break;
                        case 'jc':
                            types.push('机场规划');
                            break;
                        default:
                            break;
                    }
                    if (content['reply_xx'] != null) {
                        for (var j = 0; j < content['reply_xx'].length; j++) {
                            switch (content['reply_xx'][j]['pflx']) {
                                case '工可批复文号':
                                    if (fiveContent['gkCodes'] == '') fiveContent['gkCodes'] = content['reply_xx'][j]['pfwh'];
                                    break;
                                case '初设批复文号':
                                    if (fiveContent['csCodes'] == '') fiveContent['csCodes'] = content['reply_xx'][j]['pfwh'];
                                    break;
                                case '承诺函文号':
                                    if (fiveContent['crhCodes'] == '') fiveContent['crhCodes'] = content['reply_xx'][j]['pfwh'];
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    fiveData.push(fiveContent);
                }
                //默认状态下所有的
                var selectHtml = '';
                names.map(function (name, index) {
                    selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '">五年规划-' + types[index] + '/' + name + '</option>';
                });
                selectHtml = '<option></option>' + selectHtml;
                $('.name-select').empty().append(selectHtml);
                $.changeAll('name');
            });
        }
        //省交通建设计划
        if (/^(jt)/.test(locaType) && locaType != 'jtcx') {
            $.post('/api/get_project?project_type=gljy;syjy;zcxt;jtlw;jtzc;jtsy;jtjc', {}, function (all) {
                all = all['list'];
                var names = [],
                    fiveContent = {},
                    types = [],
                    typeCode = [],
                    xmfms = [];
                for (var i = 0; i < all.length; i++) {
                    var projectType = all[i]['project_type'],
                        jbxx = '';
                    if (/^(jt)/.test(projectType)) {
                        jbxx = all[i]['content']['SJ_JBXX'];
                        var qqgz = all[i]['content']['SJ_QQGZ'];
                        fiveContent = {
                            "type": 'jt',
                            'names': jbxx['XMMC'],
                            'ghCodes': '',
                            'gkCodes': qqgz['GKPFWH'],
                            'csCodes': qqgz['CSPFWH'],
                            'crhCodes': '',
                            'startYears': jbxx['KGN'],
                            'endYears': jbxx['WGN'],
                            'xmfm': jbxx['XMFM'],
                            'identifier': all[i]['identifier']
                        }
                    } else {
                        jbxx = all[i]['content']['GS_NDJH_XMJBXX'];
                        var ndjh = all[i]['content']['GS_NDJH_NDJYJH'];
                        fiveContent = {
                            "type": 'bu',
                            'names': jbxx['XMMC'],
                            'ghCodes': jbxx['GHBM'],
                            'gkCodes': jbxx['GKHHZPFWH'],
                            'csCodes': jbxx['CSHSGTPFWH'],
                            'crhCodes': jbxx['CRHWH'],
                            'startYears': ndjh['JSKGN'],
                            'endYears': ndjh['JSWGN'],
                            'xmfm': jbxx['XMFM'],
                            'identifier': all[i]['identifier']
                        }
                    }
                    names.push(jbxx['XMMC']);
                    fiveData.push(fiveContent);
                    xmfmData.push(fiveContent);
                    xmfms.push(jbxx['XMFM']);
                    typeCode.push(projectType);
                    switch (projectType) {
                        case 'gljy':
                            types.push('公路建议计划');
                            break;
                        case 'syjy':
                            types.push('水运建议计划');
                            break;
                        case 'zcxt':
                            types.push('支持系统建议计划');
                            break;
                        case 'jtlw':
                            types.push('公路路网');
                            jtAuto.push(all[i]);
                            break;
                        case 'jtzc':
                            types.push('公路站场');
                            jtAuto.push(all[i]);
                            break;
                        case 'jtsy':
                            types.push('水运建议');
                            jtAuto.push(all[i]);
                            break;
                        case 'jtjc':
                            types.push('民用机场');
                            jtAuto.push(all[i]);
                            break; ƒ
                        default:
                            break;
                    }
                }
                //默认状态下所有的
                var selectHtml = '';
                names.map(function (name, index) {
                    fiveData[index]['type'] == 'bu' ? selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '">部级投资计划-' + types[index] + '/' + name + '</option>' : selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + name + '</option>';
                });
                selectHtml = '<option></option>' + selectHtml;
                $('.name-select').empty().append(selectHtml);
                $.changeAll('name');
                var xmfmSelect = '';
                xmfms.map(function (xmfm, index) {
                    fiveData[index]['type'] == 'bu' ? xmfmSelect += '<option data-id="' + fiveData[index]['identifier'] + '">部级投资计划-' + types[index] + '/' + xmfm + '</option>' : xmfmSelect += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + xmfm + '</option>';
                });
                xmfmSelect = '<option></option>' + xmfmSelect;
                $('.xmfm-select').empty().append(xmfmSelect);
                $.changeAll('xmfm');
            })
        }
        //省政府投资
        if (/^(sj)/.test(locaType) && locaType != 'sjcx' && locaType != 'sjbb') {
            $.post('/api/get_project?project_type=jtlw;jtzc;jtsy;jtjc', {}, function (all) {
                all = all['list'];
                var names = [],
                    fiveContent = {},
                    types = [],
                    typeCode = [],
                    xmfms = [];
                for (var i = 0; i < all.length; i++) {
                    var jbxx = all[i]['content']['SJ_JBXX'],
                        qqgz = all[i]['content']['SJ_QQGZ'];
                    var fiveContent = {
                        'names': jbxx['XMMC'],
                        'ghCodes': '',
                        'gkCodes': qqgz['GKPFWH'],
                        'csCodes': qqgz['CSPFWH'],
                        'crhCodes': '',
                        'startYears': jbxx['KGN'],
                        'endYears': jbxx['WGN'],
                        'xmfm': jbxx['XMFM'],
                        'identifier': all[i]['identifier']
                    }
                    names.push(jbxx['XMMC']);
                    xmfms.push(jbxx['XMFM']);
                    fiveData.push(fiveContent);
                    xmfmData.push(fiveContent);
                    typeCode.push(all[i]['project_type']);
                    jtAuto.push(all[i]);
                    switch (all[i]['project_type']) {
                        case 'jtlw':
                            types.push('公路路网');
                            break;
                        case 'jtzc':
                            types.push('公路站场');
                            break;
                        case 'jtsy':
                            types.push('水运建议');
                            break;
                        case 'jtjc':
                            types.push('民用机场');
                            break;
                        default:
                            break;
                    }
                }
                //默认状态下所有的
                var selectHtml = '';
                names.map(function (name, index) {
                    selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + name + '</option>';
                });
                selectHtml = '<option></option>' + selectHtml;
                $('.name-select').empty().append(selectHtml);
                $.changeAll('name');
                var xmfmSelect = '';
                xmfms.map(function (xmfm, index) {
                    xmfmSelect += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + xmfm + '</option>';
                });
                xmfmSelect = '<option></option>' + xmfmSelect;
                $('.xmfm-select').empty().append(xmfmSelect);
                $.changeAll('xmfm');
            })
        }
        //五年规划
        if (locaType == 'tl') {
            $.post('/api/get_project?project_type=sjlw;sjzc;sjsy;sjjc;sjtz;jtlw;jtzc;jtsy;jtjc', {}, function (all) {
                all = all['list'];
                var names = [],
                    fiveContent = {},
                    types = [],
                    typeCode = [],
                    xmfms = [];
                for (var i = 0; i < all.length; i++) {
                    var jbxx = all[i]['content']['SJ_JBXX'],
                        qqgz = all[i]['content']['SJ_QQGZ'],
                        project_type = all[i]['project_type'];
                    var fiveContent = {
                        'type': /^(sj)/.test(project_type) ? 'sj' : 'jt',
                        'names': jbxx['XMMC'],
                        // 'ghCodes': '',
                        // 'gkCodes': qqgz['GKPFWH'],
                        // 'csCodes': qqgz['CSPFWH'],
                        // 'crhCodes': '',
                        'startYears': jbxx['KGN'],
                        'endYears': jbxx['WGN'],
                        'xmfm': jbxx['XMFM'],
                        'identifier': all[i]['identifier']
                    }
                    names.push(jbxx['XMMC']);
                    xmfms.push(jbxx['XMFM']);
                    fiveData.push(fiveContent);
                    xmfmData.push(fiveContent);
                    typeCode.push(project_type);
                    jtAuto.push(all[i]);
                    switch (project_type) {
                        case 'jtlw': case 'sjlw':
                            types.push('公路路网');
                            break;
                        case 'jtzc': case 'sjzc':
                            types.push('公路站场');
                            break;
                        case 'jtsy': case 'sjsy':
                            types.push('水运建议');
                            break;
                        case 'jtjc': case 'sjjc':
                            types.push('民用机场');
                            break;
                        case 'sjtz':
                            types.push('省本级基建项目');
                            break;
                        default:
                            break;
                    }
                }
                //默认状态下所有的
                var selectHtml = '';
                names.map(function (name, index) {
                    fiveData[index]['type'] == 'sj' ? selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">省级政府投资计划-' + types[index] + '/' + name + '</option>' : selectHtml += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + name + '</option>';
                });
                selectHtml = '<option></option>' + selectHtml;
                $('.name-select').empty().append(selectHtml);
                $.changeAll('name');
                var xmfmSelect = '';
                xmfms.map(function (xmfm, index) {
                    fiveData[index]['type'] == 'sj' ? xmfmSelect += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">省级政府投资计划-' + types[index] + '/' + xmfm + '</option>' : xmfmSelect += '<option data-id="' + fiveData[index]['identifier'] + '" data-type="' + typeCode[index] + '">全省交通建设计划-' + types[index] + '/' + xmfm + '</option>';
                });
                xmfmSelect = '<option></option>' + xmfmSelect;
                $('.xmfm-select').empty().append(xmfmSelect);
                $.changeAll('xmfm');
            })
        }
    },
    getJtAlready: function (locaType) {
        $.post('/api/get_project?project_type=jtlw;jtzc;jtsy;jtjc', {}, function (all) {
            all = all['list'];
            var names = [],
                fiveContent = {},
                types = [];
            for (var i = 0; i < all.length; i++) {
                var jbxx = all[i]['content']['SJ_JBXX'],
                    qqgz = all[i]['content']['SJ_QQGZ'];
                var fiveContent = {
                    'names': jbxx['XMMC'],
                    'ghCodes': '',
                    'gkCodes': qqgz['GKPFWH'],
                    'csCodes': qqgz['CSPFWH'],
                    'crhCodes': '',
                    'startYears': jbxx['KGN'],
                    'endYears': jbxx['WGN'],
                    'xmfm': jbxx['XMFM'],
                    'identifier': all[i]['identifier']
                }
                names.push(jbxx['XMMC']);
                jtData.push(fiveContent);
                switch (all[i]['project_type']) {
                    case 'jtlw':
                        types.push('公路路网');
                        break;
                    case 'jtzc':
                        types.push('公路站场');
                        break;
                    case 'jtsy':
                        types.push('水运建议');
                        break;
                    case 'jtjc':
                        types.push('民用机场');
                        break;
                    default:
                        break;
                }
            }
            //默认状态下所有的
            var selectHtml = '';
            names.map(function (name, index) {
                selectHtml += '<option data-id="' + jtData[index]['identifier'] + '">全省交通建设计划-' + types[index] + '/' + name + '</option>';
            });
            selectHtml = '<option></option>' + selectHtml;
            $('.xmName-select').empty().append(selectHtml);
            $.changeAll('xmName');
        })
    },
    changeAll: function (className) {
        $.selectClick(className);
        $('.' + className + '-select').on('change', function () {
            var selectVal = $('.' + className + '-select option:selected').html(),
                selectArr = selectVal.split('/');
            $('.' + className + '-input').val(selectArr[1]);
            $.otherAuto(selectArr[1], $('.' + className + '-select option:selected').attr('data-id'), className, $('.' + className + '-select option:selected').attr('data-type'));
        });
        $('.' + className + '-input').on('change', function () {
            $('.' + className + '-select option').addClass('none');
            if ($(this).val() == '') {
                $('.' + className + '-select option').removeClass('none');
            } else {
                $.selectClick('' + className + '');
            }
            $('.' + className + '-select option').attr('selected', false);
        });
    },
    selectClick: function (className) {
        var value = $('.' + className + '-input').val();
        $('.' + className + '-select option').each(function () {
            var optionVal = $(this).html();
            if (optionVal == '') {
                $(this).removeClass('none');
            } else if (optionVal.indexOf(value) != -1) {
                $(this).removeClass('none');
            }
        })
    },
    otherAuto: function (name, id, className, autoType) {
        var autoData = '',
            detail = '';
        switch (className) {
            case 'xmName':
                autoData = jtData;
                detail = 'names';
                break;
            case 'xmfm':
                autoData = xmfmData;
                detail = 'xmfm';
                break;
            default:
                autoData = fiveData;
                detail = 'names';
                break;
        }
        for (var i = 0; i < autoData.length; i++) {
            if (autoData[i][detail] == name && autoData[i]['identifier'] == id) {
                $('.XMMC,.name').val(autoData[i]['names']);  //项目名称
                $('.GHBM,.project_plan_code').val(autoData[i]['ghCodes']);  //项目规划编码
                $('.JSKGN,.KGN,.construction_start_year').val(autoData[i]['startYears']);  //开工年
                $('.JSWGN,.WGN,.construction_end_year').val(autoData[i]['endYears']);  //完工年
                $('.GKHHZPFWH,.GKPFWH').val(autoData[i]['gkCodes']);  //工可批复文号
                $('.CSHSGTPFWH,.CSPFWH').val(autoData[i]['csCodes']); //初设批复文号
                $('.CRHWH').val(autoData[i]['crhCodes']);  //承诺函文号
                $('.XMFM').val(autoData[i]['xmfm']); //项目赋码
            }
        }
        var lorr = top.location.pathname.split('/');
        topType = lorr[lorr.length - 1].split('.')[0];
        if (/^(jt)/.test(autoType) && autoType.substring(2, 4) == topType.substring(2, 4)) {
            for (var a = 0; a < jtAuto.length; a++) {
                if (jtAuto[a]['identifier'] == id) {
                    $('.bodyObj').each(function () {
                        var dataBody = $(this).attr('data-body');
                        if (dataBody != 'SJ_JBXX') {
                            $(this).find('.data-get').each(function () {
                                var className = $(this).attr('data-name');
                                $('.' + className).val(jtAuto[a]['content'][dataBody][className]);
                            })
                        }
                    });
                }
            }
        }

    },
    yearAuto: function (currentYear) {
        var nextYear = parseInt(currentYear) + 1,
            nnextYear = parseInt(currentYear) + 2;
        var larr = top.location.pathname.split('.')[0].split('/');
        type = larr[larr.length - 1];
        $('.currentYear').html(currentYear);
        $('.nextYear').html(nextYear);
        $('.nnextYear').html(nnextYear);   //新增
        $('.thCurrent').html('本年(' + currentYear + '年)建议计划');  //表格
        $('.thNext').html('下年(' + nextYear + '年)建议计划');
        $('.thNnext').html('下下年(' + nnextYear + '年)建议计划');
        $('.ttCurrent').html('本年度(' + currentYear + ')建议计划总投资(万元)');  //全省计划分析表
        $('.ttNext').html('下年度(' + nextYear + ')建议计划总投资(万元)');
        $('.ttNnext').html('下下年度(' + nnextYear + ')建议计划总投资(万元)');
        //省级
        if (/^(sj)/.test(type) || /^(jt)/.test(type)) {
            $('.thCurrent').html('预计到' + currentYear + '年底(单位:万元)');
            $('.thNext').html(nextYear + '年建议计划(单位:万元)');
            $('.current1').html('至' + currentYear + '年底已下达中央和省筹(万元)');
            $('.current2').html('至' + currentYear + '年底未安排部省资金');
            $('.current3').html('至' + currentYear + '年底累计完成投资(万元)');
            $('.current4').html('地市上报' + currentYear + '年计划投资');
            $('.current5').html('至' + currentYear + '年底未安排计划');
            $('.current6').html('预计到' + currentYear + '年底累计完成投资');
            $('.current7').html(currentYear + '年计划');
            $('.current8').html('比' + currentYear + '年增加');
            $('.nextYear1').html(nextYear + '年计划投资');
            $('.nextYear2').html(nextYear + '年完工项目小计');
            if (type == 'sjjc') $('.current1').html('到' + currentYear + '年底');
        } else if (/^(nc)/.test(type)) {
            $('.thCurrent1').html('本年(' + currentYear + '年)计划');
        }
    },
    addKzd: function (that) {
        var kzdHtml = '',
            xh = $('.sxh').val();
        that.parents('.kzd').find('.kzd-value').each(function () {
            var dataType = $(this).attr('data-type');
            if (dataType == 'select') {
                kzdHtml += '<td>' + $(this).find('option:selected').html() + '</td>';
            } else if (dataType == 'input') {
                kzdHtml += '<td>' + $(this).val() + '</td>';
            }
        });
        kzdHtml = '<tr>' + kzdHtml + '<td><span class="kzd_del">删除</span><span class="kzd_edit">修改</span></td></td>';
        $.sameKzd($('.kzd-table table tbody tr').length, kzdHtml, xh);
        $('.kzd-value').val('');
    },
    sameKzd: function (trLength, kzdHtml, xh) {
        if (trLength == 0) {
            $('.kzd-table table tbody').append(kzdHtml);
        } else {
            var first = $('.kzd-table table tbody tr:first-child').find('td').eq(1).html(),
                last = $('.kzd-table table tbody tr:last-child').find('td').eq(1).html();
            if (parseInt(xh) < parseInt(first)) {
                $('.kzd-table table tbody tr:first-child').before(kzdHtml);
            } else if (parseInt(xh) > parseInt(last)) {
                $('.kzd-table table tbody tr:last-child').after(kzdHtml);
            } else {
                $('.kzd-table table tbody tr').each(function (n) {
                    var currentXh = $(this).find('td').eq(1).html();
                    if (parseInt(xh) < parseInt(currentXh)) {
                        $(this).before(kzdHtml);
                        return false;
                    }
                })
            }
        }
    },
    kzdEdit: function (that) {
        that.parents('tr').find('td').removeClass('kzdCheckErr');
        var selectHtml = '<select class="kzd-value" data-type="select"><option value="">-请选择-</option><option value="1">起点</option><option value="2">讫点</option><option value="3">中间点</option></select>';
        var value = that.parents('tr').find('td').eq(0).html();
        var reg = '>' + value;
        selectHtml = selectHtml.replace(reg, ' selected>' + value);
        that.parents('tr').find('td').eq(0).html(selectHtml);
        that.parents('tr').find('td:not(":last-child")').each(function (i) {
            if (i != 0) {
                var value = $(this).html();
                $(this).html('<input value="' + value + '"/>');
            }
        })
    },
    kzdSure: function (that) {
        var cur = that.parents('tr').find('td').eq(1).children().val();
        var parentTr = that.parents('tr');
        parentTr.find('td:not(":last-child")').each(function (i) {
            if (i == 0) {
                var value = $(this).find('select option:selected').html();
                $(this).html(value);
            } else {
                $(this).html($(this).find('input').val());
            }
        });
        that.html('修改').removeClass('kzd_sure');
        var clone = parentTr.clone();
        parentTr.remove();
        $.sameKzd($('.kzd-table table tbody tr').length, clone, cur);
    },
    getJyAlready: function () {
        var larr = top.location.pathname.split('/'),
            type = larr[larr.length - 1].split('.')[0],
            item = localStorage.getItem('item'),
            status = '审核通过审批未接收';
        if (/^(sj)/.test(type)) status = '已下达';
        if (item == '全省交通建设计划') type = type.replace(/^(sj)/, 'jt');
        $.post('/api/get_project?project_type=' + type + '&status=' + encodeURI(status) + '&sub_item=true', {}, function (all) {
            all = all['list'];
            $.createItem('.item-container', all, type);  //all items
            $('.item-selectBtn').on('click', function () {
                $.selectItem(all);
                $('#ghitem').addClass('modalActive').siblings().removeClass('modalActive');
                $('#ghitemModal').show().siblings().hide();
                $('#ghitemSelect').hide();
            });
            // 编辑子项目
            $('body').on('click', '.item-edit', function () {
                var identifier = $(this).parents('tr').attr('data-id');
                $('#ghitemEdit').show().addClass('modalActive').siblings().removeClass('modalActive');
                $('#ghxzModal').show().siblings().hide();
                $('.xzBtn').hide();
                $('.xgBtn').show();
                $('.confirmBtn').eq(1).attr('data-type', 'editNew').attr('disabled', false);
                var txt = $(this).parent().next().html(),
                    allItem = addItemArr.concat(selectItemArr),
                    allData = [];
                $.each(allItem, function (key, value) {
                    var obj = {};
                    $.each(value, function (k, v) {
                        if (k == 'content') {
                            $.each(v, function (ki, vi) {
                                obj[ki] = vi;
                            })
                        } else {
                            obj[k] = v;
                        }
                    })
                    allData.push(obj);
                })
                editMatch(identifier, txt, allData);
            });
        });
    },
    selectItem: function (all) {
        var larr = top.location.pathname.split('/'),
            type = larr[larr.length - 1].split('.')[0],
            selectArr = [];
        $('.item-container tbody tr>td:first-child input[type="checkbox"]').each(function () {
            if ($(this).is(':checked')) {
                var index = parseInt($(this).parents('tr').attr('data-xh'));
                selectArr.push(all[index]);
            }
        });
        selectItemArr = selectArr;
        $.addItem('.selected-container', type);
        // $.createItem('.selected-container', selectArr, type);
    },
    addItem: function (tableName, type) {
        $.createItem('.selected-container', addItemArr.concat(selectItemArr), type);
    },
    createItem: function (tableName, all, type) {
        var tdHtml = '',
            trHtml = '';
        var tableArr = getThead(tableName)[1];
        for (var i = 0; i < all.length; i++) {
            tdHtml = '';
            var jbxx = (/^(sj)/.test(type) || /^(jt)/.test(type)) ? all[i]['content']['SJ_JBXX'] : jbxx = all[i]['content']['GS_NDJH_XMJBXX'];
            for (var j = 0; j < tableArr.length; j++) {
                if (tableArr[j] == 'operate') {
                    var hasBool = false;
                    if (addItemArr.length == 0) {
                        hasBool = false;
                    } else {
                        for (var a = 0; a < addItemArr.length; a++) {
                            if (addItemArr[a]['identifier'] == all[i]['identifier']) hasBool = true;
                        }
                    }
                    hasBool ? tdHtml += '<td><span class="item-edit">编辑</span></td>' : tdHtml += '<td></td>';
                } else if (tableArr[j] == 'PC' || tableArr[j] == 'XMLXDM' || tableArr[j] == 'XMAPFS' || tableArr[j] == 'THBZ' || tableArr[j] == 'XMLB' || tableArr[j] == 'JHXZ') {
                    jbxx[tableArr[j]] == '' ? tdHtml += '<td></td>' : tdHtml += '<td>' + $('.' + tableArr[j] + ' option[value="' + jbxx[tableArr[j]] + '"]').html() + '</td>';
                } else {
                    if (tableArr[j] == 'GKPFWH' || tableArr[j] == 'CSPFWH') {
                        var value = all[i]['content']['SJ_QQGZ'][tableArr[j]];
                        value == undefined ? tdHtml += '<td></td>' : tdHtml += '<td>' + value + '</td>';
                    } else if (tableArr[j] == 'SSDW') {
                        var value = all[i]['content']['SJ_SSDW'][tableArr[j]];
                        value == undefined ? tdHtml += '<td></td>' : tdHtml += '<td>' + value + '</td>';
                    } else {
                        tdHtml += '<td>' + jbxx[tableArr[j]] + '</td>';
                    }
                }
            }
            tableName == '.item-container' ? trHtml += '<tr data-id="' + all[i]['identifier'] + '" data-xh="' + i + '"><td><input type="checkbox"></td>' + tdHtml + '</tr>' : trHtml += '<tr data-id="' + all[i]['identifier'] + '" data-xh="' + i + '">' + tdHtml + '</tr>';
        }
        $(tableName + '>tbody').empty().append(trHtml);
    }
});

function approve(iconName) {
    $('#tree1').treeview({
        animated: "fast",
        control: "#treecontrol",
        // persist: "cookie",
        // cookieId: "treeview-black"
    });
    $('.closeIcon').on('click', function () {
        $(".treeBox_2").hide();
        $('.treeSecLevel').hide();
    });
    $('.modal-body').on('click', iconName, function (e) {
        e.stopPropagation();
        $('.treeBox_2').show();
        $('.treeBox_2').drag('treeBox_2', '.treeBox_2')
        $('.treeActive').removeClass('treeActive');
        $.treeNode1('.inp_division_2', 2);
        $.treeNode2($('.inp_division_2'), 2, $(this).prev());
    });
}

//省新增历年项目
function addLnxm() {
    var addData = {},
        add = {
            "identifier": guid(),
            "modified": "0",
            "status": '',
            "project_type": $('[id^=lnxm_sj].active,[id^=lnxm_jt].active', parent.document).attr('data-type'),
            "user_name": localStorage.user_name,
            "content": {}
        },
        upData = {};
    //获取信息
    $('.tabContainer').find('.data-get').each(function (a) {
        var className = $(this).attr('data-name');
        if ($('.' + className).hasClass('input') || $('.' + className).hasClass('textarea')) {
            if (className == 'BBWJ') {
                addData['bbid'] = $('.' + className).attr('data-id');
                addData['bburl'] = $('.' + className).attr('data-url');
            } else {
                addData[className] = $('.' + className).val();
            }
        } else if ($('.' + className).hasClass("select")) {
            addData[className] = $('.' + className).html();
        }
    });
    add.content = $.extend({}, add.content, addData);
    var data = JSON.stringify(add);
    $.ajax({
        type: 'post',
        url: '/api/add_project?user_name=' + localStorage.user_name,
        data: data,
        success: function (result) {
            $('.tabContainer modal-body .data-get').children('input').val('');
            $('#myModalgh').modal('hide');
            location.reload();
        },
        error: function (error) {
            console.log(error);
        }
    });
}

//获取各个表的表头name
function getThead(className) {
    var tableClass = className ? className : '.data-table',
        length = $(tableClass + '>thead>tr').length,
        thArr = [],
        thClass = [];
    if ($(tableClass + '>thead>tr').length == 1) {
        //一级表头
        $(tableClass + '>thead>tr').eq(0).children().each(function (i, th) {
            thArr.push(th.innerText);
            if ($(th).attr('data-head') != undefined) thClass.push($(th).attr('data-head'));
        })
    } else if ($(tableClass + '>thead>tr').length == 2) {
        //二级表头
        var colIndex1 = colLength1 = 0;
        $(tableClass + '>thead>tr').eq(0).children().each(function (i, th) {
            colLength1 = th.colSpan;
            if (colLength1 > 1) {
                for (var j = colIndex1; j < colIndex1 + colLength1; j++) {
                    thArr.push($(tableClass + '>thead>tr').eq(1).children()[j].innerText);
                    thClass.push($($(tableClass + '>thead>tr').eq(1).children()[j]).attr('data-head'));
                }
                colIndex1 = colIndex1 + colLength1;
            } else {
                thArr.push(th.innerText);
                if ($(th).attr('data-head') != undefined) thClass.push($(th).attr('data-head'));
            }
        });
    } else if ($(tableClass + '>thead>tr').length == 3) {
        //三级表头
        var colIndex1 = colIndex2 = 0,
            colLength1 = colLength2 = 1,
            moreLength1 = 1;
        $(tableClass + '>thead>tr').eq(0).children().each(function (i, th) {
            colLength1 = th.colSpan;
            if (colLength1 > 1) {
                for (var a = colIndex1; a < colIndex1 + colLength1 - (moreLength1 - 1); a++) {
                    colLength2 = $(tableClass + '>thead>tr').eq(1).children()[a].colSpan;
                    if (colLength2 > 1) {
                        moreLength1 += colLength2 - 1;
                        for (var b = colIndex2; b < colIndex2 + colLength2; b++) {
                            thArr.push($(tableClass + '>thead>tr').eq(2).children()[b].innerText);
                            thClass.push($($(tableClass + '>thead>tr').eq(2).children()[b]).attr('data-head'));
                        }
                        colIndex2 = colIndex2 + colLength2;
                    } else {
                        thArr.push($(tableClass + '>thead>tr').eq(1).children()[a].innerText);
                        thClass.push($($(tableClass + '>thead>tr').eq(1).children()[a]).attr('data-head'));
                    }
                }
                colIndex1 = colIndex1 + colLength1 - (moreLength1 - 1);
                moreLength1 = 1;
            } else {
                thArr.push(th.innerText);
                if ($(th).attr('data-head') != undefined) thClass.push($(th).attr('data-head'));
            }
        });
    } else if ($(tableClass + '>thead>tr').length == 4) {
        //四级表头
        var colIndex1 = colIndex2 = colIndex3 = 0,
            colLength1 = colLength2 = colLength3 = 1,
            moreLength1 = moreLength2 = 1;
        $(tableClass + '>thead>tr').eq(0).children().each(function (i, th) {
            colLength1 = th.colSpan;
            if (colLength1 > 1) {
                for (var a = colIndex1; a < colIndex1 + colLength1 - (moreLength1 - 1); a++) {
                    colLength2 = $(tableClass + '>thead>tr').eq(1).children()[a].colSpan;
                    if (colLength2 > 1) {
                        moreLength1 += colLength2 - 1;
                        for (var b = colIndex2; b < colIndex2 + colLength2 - (moreLength2 - 1); b++) {
                            colLength3 = $(tableClass + '>thead>tr').eq(2).children()[b].colSpan;
                            if (colLength3 > 1) {
                                moreLength2 += colLength3 - 1;
                                for (var c = colIndex3; c < colIndex3 + colLength3; c++) {
                                    thArr.push($(tableClass + '>thead>tr').eq(3).children()[c].innerText);
                                    thClass.push($($(tableClass + '>thead>tr').eq(3).children()[c]).attr('data-head'));
                                }
                                colIndex3 = colIndex3 + colLength3;
                            } else {
                                thArr.push($(tableClass + '>thead>tr').eq(2).children()[b].innerText);
                                thClass.push($($(tableClass + '>thead>tr').eq(2).children()[b]).attr('data-head'));
                            }
                        }
                        colIndex2 = colIndex2 + colLength2 - (moreLength2 - 1);
                        moreLength2 = 1;
                    } else {
                        thArr.push($(tableClass + '>thead>tr').eq(1).children()[a].innerText);
                        thClass.push($($(tableClass + '>thead>tr').eq(1).children()[a]).attr('data-head'));
                    }
                }
                colIndex1 = colIndex1 + colLength1 - (moreLength1 - 1);
                moreLength1 = 1;
            } else {
                thArr.push(th.innerText);
                if ($(th).attr('data-head') != undefined) thClass.push($(th).attr('data-head'));
            }
        });
    } else if ($(tableClass + '>thead>tr').length == 5) {
        //五级表头
        var colIndex1 = colIndex2 = colIndex3 = colIndex4 = 0,
            colLength1 = colLength2 = colLength3 = colLength4 = 1,
            moreLength1 = moreLength2 = moreLength3 = 1;
        $(tableClass + '>thead>tr').eq(0).children().each(function (i, th) {
            colLength1 = th.colSpan;
            if (colLength1 > 1) {
                for (var a = colIndex1; a < colIndex1 + colLength1 - (moreLength1 - 1); a++) {
                    colLength2 = $(tableClass + '>thead>tr').eq(1).children()[a].colSpan;
                    if (colLength2 > 1) {
                        moreLength1 += colLength2 - 1;
                        for (var b = colIndex2; b < colIndex2 + colLength2 - (moreLength2 - 1); b++) {
                            colLength3 = $(tableClass + '>thead>tr').eq(2).children()[b].colSpan;
                            if (colLength3 > 1) {
                                moreLength2 += colLength3 - 1;
                                for (var c = colIndex3; c < colIndex3 + colLength3 - (moreLength3 - 1); c++) {
                                    colLength4 = $(tableClass + '>thead>tr').eq(3).children()[c].colSpan;
                                    if (colLength4 > 1) {
                                        moreLength3 += colLength4 - 1;
                                        for (var d = colIndex4; d < colIndex4 + colLength4; d++) {
                                            thArr.push($(tableClass + '>thead>tr').eq(4).children()[d].innerText);
                                            thClass.push($($(tableClass + '>thead>tr').eq(4).children()[d]).attr('data-head'));
                                        }
                                        colIndex4 = colIndex4 + colLength4;
                                    } else {
                                        thArr.push($(tableClass + '>thead>tr').eq(3).children()[c].innerText);
                                        thClass.push($($(tableClass + '>thead>tr').eq(3).children()[c]).attr('data-head'));
                                    }
                                }
                                colIndex3 = colIndex3 + colLength3 - (moreLength3 - 1);
                            } else {
                                thArr.push($(tableClass + '>thead>tr').eq(2).children()[b].innerText);
                                thClass.push($($(tableClass + '>thead>tr').eq(2).children()[b]).attr('data-head'));
                            }
                        }
                        colIndex2 = colIndex2 + colLength2 - (moreLength2 - 1);
                        moreLength2 = 1;
                    } else {
                        thArr.push($(tableClass + '>thead>tr').eq(1).children()[a].innerText);
                        thClass.push($($(tableClass + '>thead>tr').eq(1).children()[a]).attr('data-heaad'));
                    }
                }
                colIndex1 = colIndex1 + colLength1 - (moreLength1 - 1);
                moreLength1 = 1;
            } else {
                thArr.push(th.innerText);
                if ($(th).attr('data-head') != undefined) thClass.push($(th).attr('data-head'));
            }
        });
    }
    return [thArr, thClass];
}

//报表新增
function addReport() {
    var addData = {},
        add = {
            "identifier": guid(),
            "modified": "0",
            "status": '未确认',
            "user_name": localStorage.user_name,
            "content": {
                "bb": [],
            }
        },
        upData = {},
        upOrg = "";
    //获取报表信息
    $('.tabContainer').find('.data-get').each(function (a) {
        var className = $(this).attr('data-name');
        if ($('.' + className).hasClass('input') || $('.' + className).hasClass('textarea')) {
            if (className == 'BBWJ') {
                addData['bbid'] = $('.' + className).attr('data-id');
                addData['bburl'] = $('.' + className).attr('data-url');
            } else if (className == 'SJSBJG') {
                upOrg = $('.' + className).val();
            } else {
                addData[className] = $('.' + className).val();
            }
        } else if ($('.' + className).hasClass("select")) {
            addData[className] = $('.' + className).html();
        }
    });
    upOrg = upOrg.replace(/-厅管厅属-/g, '-');
    addData['SJSBJG'] = upOrg;
    var uporgArr = upOrg.split(';');
    for (var c = 0; c < uporgArr.length; c++) {
        upData = {};
        upData['title'] = uporgArr[c];
        upData['bbstatus'] = "未接收";
        add.content.bb.push(upData);
    }
    var larr = top.location.pathname.split('.')[0].split('/');
    type = larr[larr.length - 1]
    add.project_type = type;
    add.to_division = $(".first_trial").attr('disabled') == 'disabled' ? $(".second_trial.select").find("option:selected").val() : $(".first_trial").attr('data-verCode');
    add.to_career = $(".first_trial").attr('disabled') == 'disabled' ? $(".second_trial.select").find("option:selected").attr('data-verName') : $(".first_trial").attr('data-verName');
    addData.up_org = localStorage.division_code + localStorage.career;
    addData.makeHead = getMake()[0];
    addData.makeBody = getMake()[1];
    add.category = addData.project_kind;
    add.content = $.extend({}, add.content, addData);
    if (!$('#ghxzModal').find('.data-get').children().hasClass('checkErr')) {
        var data = JSON.stringify(add);
        $.ajax({
            type: 'post',
            url: '/api/add_project?user_name=' + localStorage.user_name,
            data: data,
            success: function (result) {
                $('.tabContainer modal-body .data-get').children('input').val('');
                $('#myModalgh').modal('hide');
                location.reload();
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
}

//制表
function tableMake() {
    $('.make-table').on('click', function () {
        $('.makeContainer').removeClass('none');
    });
    $('.make-btn').on('click', function () {
        var row = $('.make-row').val(),  //行
            column = $('.make-column').val(),  //列
            tdHtml = '',
            theadHtml = '',
            tbodyHtml = '';
        for (var i = 0; i < column; i++) {
            tdHtml += '<td><input type="text" /></td>';
        }
        theadHtml = '<tr>' + tdHtml + '</tr>';
        $('.makeTable thead').empty().append(theadHtml);
        for (var j = 0; j < row - 1; j++) {
            tbodyHtml += '<tr>' + tdHtml + '</tr>';
        }
        $('.makeTable tbody').empty().append(tbodyHtml);
    });
}

//制表内容获取
function getMake() {
    var makeHead = [],
        makeBody = [],
        maketd = [];
    $('.makeTable thead tr>td').each(function () {
        makeHead.push($(this).find('input').val());
    });
    $('.makeTable tbody>tr').each(function () {
        maketd = [];
        $(this).find('td').each(function () {
            maketd.push($(this).find('input').val());
        });
        makeBody.push(maketd);
    });
    return [makeHead, makeBody];
}

function Page(xh) {
    var xhNum = 0,
        xhTotal = 0,
        num = 1,
        numArr = [0];
    for (var i = 0; i < xh; i++) {
        xhNum = $('.data-table>tbody>tr.first').eq(i).attr('data-row');
        xhTotal += parseInt(xhNum);
        if (Math.floor(xhTotal / 10) == num) {
            numArr.push(i + 1);
            num++;
        }
        if (i == xh - 1 && numArr[numArr.length - 1] != xh) {
            numArr.push(i + 1);
        }
    }
    $(".pageTotally").val(numArr.length - 1);  //总页数
    return numArr;
}

function currentPage2(firstPage, lastPage) {
    (firstPage == undefined || lastPage == undefined) ? $('.inputsTyle').eq(2).val('0') : $('.inputsTyle').eq(2).val(lastPage - firstPage); //每页条数
    $('.data-table>tbody>tr').addClass('none');
    var total = 0;
    //开始的total
    var firstTotal = 0,
        lastTotal = 0;
    for (var a = 0; a < firstPage; a++) {
        firstTotal += parseInt($('.data-table>tbody>tr.first').eq(a).attr('data-row'));
    }
    for (var b = 0; b < lastPage; b++) {
        lastTotal += parseInt($('.data-table>tbody>tr.first').eq(b).attr('data-row'));
    }
    for (var f = firstTotal; f < lastTotal; f++) {
        $('.data-table>tbody>tr').eq(f).removeClass('none');
    }
}

//报表制作表格
function bbMakeTable(obj, currentPage, everyNumber) {
    var trStr = "",
        tableArr = getThead()[1];
    for (var i = 0; i < obj.length; i++) {
        var tdStr = "";
        var xh = (parseInt(currentPage - 1) * 10) + i - 0 + 1;
        for (var j = 0, len = tableArr.length; j < len; j++) {
            if (tableArr[j] == 'XH') {
                tdStr += '<td>' + xh + '</td>';
            } else if (tableArr[j] == 'status') {
                tdStr += '<td class="status">' + decodeURI(obj[i][tableArr[j]]) + '</td>';
            } else if (tableArr[j] == 'bb_operate') {
                //报表制作操作
                tdStr += '<td class="operation" data-index="' + xh + '">' +
                    '<span class="op-sure">确认</span>' +
                    '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                    '<span class="op-delete">删除</span>' +
                    '</td>';
            } else if (tableArr[j] == 'lnxm_operate') {
                tdStr += '<td class="operation" data-index="' + xh + '">' +
                    '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                    '<span class="op-delete" data-type="lnxm">删除</span>' +
                    '</td>';
            } else if (obj[i][tableArr[j]] == undefined) {
                tdStr += '<td></td>';
            } else {
                tdStr += '<td>' + obj[i][tableArr[j]] + '</td>';
            }
        }
        trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
    }
    $('#bbMakeTable>tbody').empty().append(trStr);
    if (!$('.data-table').hasClass('data-table1')) $('.data-table').fixTable(4);
    var totalPage = Math.ceil(totalNum / everyNum);  //总页数
    var everyPage = obj.length;   //当前页条数
    $('.inputsTyle').eq(1).val(totalPage);
    $('.inputsTyle').eq(2).val(everyPage);
    $('.inputsTyle').eq(4).val(totalNum);
}

//报表上报表格
function bbUploadTable(obj, currentPage, everyNumber) {
    var trStr = "",
        tableArr = getThead()[1],
        xh = 0,
        currentName = devisionc[localStorage.getItem('division_code')] + '-' + localStorage.getItem('career');
    for (var i = 0; i < obj.length; i++) {
        var tdStr = "";
        var uploadVal = obj[i]['SJSBJG'].split(';');
        var xh = (parseInt(currentPage - 1) * 10) + i - 0 + 1;
        if (localStorage.getItem('division_code') == '330000') {
            //省局以上单位、制表机构?
            if (uploadVal.length == 1) {
                //单个数据上报机构
                var wjArr = obj[i].bb[0]["wj"],
                    wjBool = false;
                wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                //无上报文件
                if (!wjBool) {
                    for (var j = 0, len = tableArr.length; j < len; j++) {
                        if (tableArr[j] == 'XH') {
                            tdStr += '<td>' + xh + '</td>';
                        } else if (tableArr[j] == 'BBMC') {
                            tdStr += '<td class="bbname">' + obj[i][tableArr[j]] + '</td>';
                        } else if (tableArr[j] == 'bbstatus') {
                            tdStr += '<td class="bbstatus">' + obj[i].bb[0].bbstatus + '</td>'
                        } else if (tableArr[j] == 'ZBJG') {
                            tdStr += '<td class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                        } else if (tableArr[j] == 'up_operate') {
                            //报表上报任务管理报表操作
                            tdStr += '<td class="operation">' +
                                '<span class="bb_upload_accept" data-index="0">接收</span>' +
                                '<span class="bbup" data-index="0" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                '</td>';
                        } else if (tableArr[j] == 'sb_operate') {
                            //文件上报操作
                            tdStr += '<td class="operation">' +
                                '<span class="op-download" data-id="' + obj[i]['sbid'] + '" data-url="' + obj[i]['sburl'] + '">下载</span>' +
                                '<span>删除</span>' +
                                '</td>';
                        } else if (obj[i][tableArr[j]] == undefined) {
                            tdStr += '<td></td>';
                        } else {
                            tdStr += '<td>' + obj[i][tableArr[j]] + '</td>';
                        }
                    }
                    //省局以上单位、制表机构可查看全部报表，上报机构只能查看操作关于本机构报表
                    currentName == uploadVal[0] ? trStr += "<tr class='first' data-row='1' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='1' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
                } else {
                    var wjLength = wjArr.length;
                    for (var e in wjArr) {
                        tdStr = '';
                        for (var j = 0, len = tableArr.length; j < len; j++) {
                            if (e == 0) {
                                //单条上报文件
                                if (tableArr[j] == 'XH') {
                                    tdStr += '<td rowspan="' + wjLength + '">' + xh + '</td>';
                                } else if (tableArr[j] == 'BBMC') {
                                    tdStr += '<td class="bbname" rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                } else if (tableArr[j] == 'bbstatus') {
                                    tdStr += '<td class="bbstatus" rowspan="' + wjLength + '">' + obj[i].bb[0].bbstatus + '</td>'
                                } else if (tableArr[j] == 'ZBJG') {
                                    tdStr += '<td class="uploadorg" rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                } else if (tableArr[j] in wjArr[e]) {
                                    tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                } else if (tableArr[j] == 'up_operate') {
                                    //报表上报任务管理报表操作
                                    tdStr += '<td class="operation" rowspan="' + wjLength + '">' +
                                        '<span class="bb_upload_accept" data-index="0">接收</span>' +
                                        '<span class="bbup" data-index="0" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                        '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                        '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                        '</td>';
                                } else if (tableArr[j] == 'sb_operate') {
                                    //文件上报操作
                                    tdStr += '<td class="operation">' +
                                        '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                        '<span class="wj_delete" data-bb="0" data-index="' + e + '">删除</span>' +
                                        '</td>';
                                } else if (obj[i][tableArr[j]] == undefined) {
                                    tdStr += '<td rowspan="' + wjLength + '"></td>';
                                } else {
                                    tdStr += '<td rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                }
                            } else {
                                //多条上报文件
                                if (tableArr[j] in wjArr[e]) {
                                    tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                } else if (tableArr[j] == 'sb_operate') {
                                    //文件上报操作
                                    tdStr += '<td class="operation">' +
                                        '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                        '<span class="wj_delete" data-bb="0" data-index="' + e + '">删除</span>' +
                                        '</td>';
                                }
                            }
                        }
                        e == 0 ? (currentName == uploadVal[0] ? trStr += "<tr class='first' data-row='" + wjLength + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + wjLength + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (currentName == uploadVal[0] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                    }
                }
            } else {
                //多个数据上报机构
                //获取rowspan的值
                var rowVal = 0;
                for (var a in uploadVal) {
                    var wjArr = obj[i].bb[a]["wj"];
                    wjArr == undefined ? rowVal += 1 : (wjArr.length == 0 ? rowVal += 1 : rowVal += wjArr.length);
                }
                for (var m in uploadVal) {
                    tdStr = '';
                    var wjArr = obj[i].bb[m]["wj"],
                        wjBool = false;
                    wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                    //无上报文件
                    if (!wjBool) {
                        for (var j = 0, len = tableArr.length; j < len; j++) {
                            if (tableArr[j] == 'XH') {
                                if (m == 0) {
                                    tdStr += '<td rowspan="' + uploadVal.length + '">' + xh + '</td>';
                                }
                            } else if (tableArr[j] == 'BBMC') {
                                tdStr += '<td class="bbname">' + obj[i][tableArr[j]] + '</td>';
                            } else if (tableArr[j] == 'ZBJG') {
                                tdStr += '<td class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                            } else if (tableArr[j] == 'SJSBJG') {
                                tdStr += '<td>' + uploadVal[m] + '</td>';
                            } else if (tableArr[j] == 'bbstatus') {
                                tdStr += '<td class="bbstatus">' + obj[i].bb[m].bbstatus + '</td>'
                            } else if (tableArr[j] == 'status') {
                                tdStr += "<td>未接收</td>";
                            } else if (tableArr[j] == 'up_operate') {
                                //报表上报任务管理报表操作
                                tdStr += '<td class="operation">' +
                                    '<span class="bb_upload_accept" data-index="' + m + '">接收</span>' +
                                    '<span class="bbup" data-index="' + m + '" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                    '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                    '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                    '</td>';
                            } else if (tableArr[j] == 'sb_operate') {
                                //文件上报操作
                                tdStr += '<td class="operation">' +
                                    '<span class="op-download" data-id="' + obj[i]['sbid'] + '" data-url="' + obj[i]['sburl'] + '">下载</span>' +
                                    '<span>删除</span>' +
                                    '</td>';
                            } else if (obj[i][tableArr[j]] == undefined) {
                                tdStr += '<td></td>';
                            } else {
                                tdStr += '<td>' + obj[i][tableArr[j]] + '</td>';
                            }
                        }
                        m == 0 ? (currentName == uploadVal[m] ? trStr += "<tr class='first' data-row='" + uploadVal.length + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + uploadVal.length + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (currentName == uploadVal[m] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                    } else {
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                if (e == 0) {
                                    if (tableArr[j] == 'XH') {
                                        if (m == 0) {
                                            tdStr += '<td rowspan="' + rowVal + '">' + xh + '</td>';
                                        }
                                    } else if (tableArr[j] == 'BBMC') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="bbname">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'ZBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'SJSBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + uploadVal[m] + '</td>';
                                    } else if (tableArr[j] == 'bbstatus') {
                                        tdStr += '<td class="bbstatus" rowspan="' + wjArr.length + '">' + obj[i].bb[m].bbstatus + '</td>'
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'up_operate') {
                                        //报表上报任务管理报表操作
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="operation">' +
                                            '<span class="bb_upload_accept" data-index="' + m + '">接收</span>' +
                                            '<span class="bbup" data-index="' + m + '" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                            '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                            '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                            '</td>';
                                    } else if (tableArr[j] == 'sb_operate') {
                                        //文件上报操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_delete" data-bb="' + m + '" data-index="' + e + '">删除</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjArr.length + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'sb_operate') {
                                        //文件上报操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_delete" data-bb="' + m + '" data-index="' + e + '">删除</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == 0 ? (currentName == uploadVal[m] ? trStr += "<tr class='first' data-row='" + rowVal + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + rowVal + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (currentName == uploadVal[m] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                        }
                    }
                }
            }
        } else {
            //所登为上报机构?
            for (var m in uploadVal) {
                if (uploadVal[m] == currentName) {
                    tdStr = '';
                    var wjArr = obj[i].bb[m]['wj'],
                        wjBool = false;
                    wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                    //无上报文件
                    if (!wjBool) {
                        for (var j = 0, len = tableArr.length; j < len; j++) {
                            if (tableArr[j] == 'XH') {
                                tdStr += '<td>' + xh + '</td>';
                            } else if (tableArr[j] == 'BBMC') {
                                tdStr += '<td class="bbname">' + obj[i][tableArr[j]] + '</td>';
                            } else if (tableArr[j] == 'bbstatus') {
                                tdStr += '<td class="bbstatus">' + obj[i].bb[m].bbstatus + '</td>'
                            } else if (tableArr[j] == 'ZBJG') {
                                tdStr += '<td class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                            } else if (tableArr[j] == 'SJSBJG') {
                                tdStr += '<td>' + uploadVal[m] + '</td>';
                            } else if (tableArr[j] == 'up_operate') {
                                //报表上报任务管理报表操作
                                tdStr += '<td class="operation">' +
                                    '<span class="bb_upload_accept" data-index="' + m + '">接收</span>' +
                                    '<span class="bbup" data-index="' + m + '" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                    '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                    '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                    '</td>';
                            } else if (tableArr[j] == 'sb_operate') {
                                //文件上报操作
                                tdStr += '<td class="operation">' +
                                    '<span class="op-download" data-id="' + obj[i]['sbid'] + '" data-url="' + obj[i]['sburl'] + '">下载</span>' +
                                    '<span>删除</span>' +
                                    '</td>';
                            } else if (obj[i][tableArr[j]] == undefined) {
                                tdStr += '<td></td>';
                            } else {
                                tdStr += '<td>' + obj[i][tableArr[j]] + '</td>';
                            }
                        }
                        trStr += "<tr class='first' data-row='1' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
                    } else {
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                //单条文件?
                                if (e == 0) {
                                    if (tableArr[j] == 'XH') {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + xh + '</td>'
                                        // if (m == 0) {
                                        //     tdStr += '<td rowspan="' + wjArr.length + '">' + xh + '</td>';
                                        // }
                                    } else if (tableArr[j] == 'BBMC') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="bbname">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'ZBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'SJSBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + uploadVal[m] + '</td>';
                                    } else if (tableArr[j] == 'bbstatus') {
                                        tdStr += '<td class="bbstatus" rowspan="' + wjArr.length + '">' + obj[i].bb[m].bbstatus + '</td>'
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'up_operate') {
                                        //报表上报任务管理报表操作
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="operation">' +
                                            '<span class="bb_upload_accept" data-index="' + m + '">接收</span>' +
                                            '<span class="bbup" data-index="' + m + '" data-toggle="modal" data-target="#myModalgh">上报</span>' +
                                            '<span class="op-download" data-id="' + obj[i]['bbid'] + '" data-url="' + obj[i]['bburl'] + '">下载</span>' +
                                            '<span class="make-modal" data-toggle="modal" data-target="#makeModalgh">查看</span>' +
                                            '</td>';
                                    } else if (tableArr[j] == 'sb_operate') {
                                        //文件上报操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_delete" data-bb="' + m + '" data-index="' + e + '">删除</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjArr.length + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'sb_operate') {
                                        //文件上报操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_delete" data-bb="' + m + '" data-index="' + e + '">删除</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == 0 ? trStr += "<tr class='first' data-row='" + wjArr.length + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
                        }
                    }
                }
            }
        }
    }
    $('#bbUploadTable>tbody').empty().append(trStr);
    var totalPage = Math.ceil(totalNum / everyNum);  //总页数
    var everyPage = obj.length;   //当前页条数
    $('.inputsTyle').eq(1).val(totalPage);
    $('.inputsTyle').eq(2).val(everyPage);
    $('.inputsTyle').eq(4).val(totalNum);
}

// 制表查看
function makeSee(that) {
    var projectId = that.parent().parent().attr('data-id'),
        makeHead = '',
        makeBody = '',
        headHtml = '',
        bodyTd = '',
        bodyHtml = '';
    for (var i = 0; i < data.length; i++) {
        if (data[i]['identifier'] == projectId) {
            makeHead = data[i]['makeHead'];
            makeBody = data[i]['makeBody'];
            break;
        }
    }
    if (makeHead == undefined && makeBody == undefined) {
        headHtml = '';
        bodyHtml = '';
    } else {
        for (var j = 0; j < makeHead.length; j++) {
            headHtml += '<td>' + makeHead[j] + '</td>';
        }
        headHtml = '<tr>' + headHtml + '</tr>';
        for (var a = 0; a < makeBody.length; a++) {
            bodyTd = '';
            for (var b = 0; b < makeBody[a].length; b++) {
                bodyTd += '<td>' + makeBody[a][b] + '</td>';
            }
            bodyHtml += '<tr>' + bodyTd + '</tr>';
        }
    }
    $('.makeSee thead').empty().append(headHtml);
    $('.makeSee tbody').empty().append(bodyHtml);
    $('.make-export').on('click', function () {
        $('.makeSee').tableExport({
            fileName: '制表',
            type: 'excel'
        })
    });
}

//数据接收及审核管理表格
function bbAcceptTable(obj, currentPage, everyNumber) {
    var trStr = "",
        tableArr = getThead()[1];
    var currentName = devisionc[localStorage.getItem('division_code')] + '-' + localStorage.getItem('career');
    for (var i = 0; i < obj.length; i++) {
        var tdStr = "",
            bbArr = obj[i]["bb"];
        var uploadVal = obj[i]['SJSBJG'].split(';');
        var xh = (parseInt(currentPage - 1) * 10) + i - 0 + 1;
        if (localStorage.getItem('division_code') == '330000') {
            //省局及以上单位、制表机构?
            for (var k = 0; k < bbArr.length; k++) {
                //文件是否存在
                var currentK = [],
                    bbBool = false;
                bbBool = bbArr[k]["wj"] == undefined ? false : (bbArr[k]["wj"].length == 0 ? false : true);
                if (bbBool) {
                    if (uploadVal.length == 1) {
                        //单个数据上报机构
                        var wjArr = obj[i].bb[0]["wj"],
                            wjLength = wjArr.length;
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                if (e == 0) {
                                    //单条上报文件
                                    if (tableArr[j] == 'XH') {
                                        tdStr += '<td rowspan="' + wjLength + '">' + xh + '</td>';
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_accept') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="wj_accept" data-bb="0" data-index="' + e + '">接收</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_sh" data-bb="0" data-index="' + e + '" data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjLength + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    //多条上报文件
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_accept') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="wj_accept" data-bb="0" data-index="' + e + '">接收</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_sh" data-bb="0" data-index="' + e + '" data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == 0 ? (currentName == wjArr[e]['SHJG'] ? trStr += "<tr class='first' data-row='" + wjLength + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + wjLength + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (currentName == wjArr[e]['SHJG'] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                        }
                    } else {
                        //多个数据上报机构
                        //获取rowspan的值
                        var rowVal = 0;
                        for (var a in uploadVal) {
                            var wjArr = obj[i].bb[a]["wj"];
                            if (wjArr == undefined) {
                                rowVal = rowVal;
                            } else {
                                if (wjArr.length == 0) {
                                    rowVal = rowVal;
                                } else {
                                    rowVal += wjArr.length;
                                    currentK.push(a);
                                }
                            }
                        }
                        tdStr = '';
                        var wjBool = false,
                            wjArr = bbArr[k]["wj"];
                        wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                        if (wjBool) {
                            for (var e in wjArr) {
                                tdStr = '';
                                for (var j = 0, len = tableArr.length; j < len; j++) {
                                    if (e == 0) {
                                        if (tableArr[j] == 'XH') {
                                            if (k == currentK[0]) {
                                                tdStr += '<td rowspan="' + rowVal + '">' + xh + '</td>';
                                            }
                                        } else if (tableArr[j] == 'SJSBJG') {
                                            tdStr += '<td rowspan="' + wjArr.length + '">' + bbArr[k]["title"] + '</td>';
                                        } else if (tableArr[j] in wjArr[e]) {
                                            tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                        } else if (tableArr[j] == 'wj_accept') {
                                            //操作
                                            tdStr += '<td class="operation">' +
                                                '<span class="wj_accept" data-bb="' + k + '" data-index="' + e + '">接收</span>' +
                                                '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                                '<span class="wj_sh"  data-bb="' + k + '" data-index="' + e + '" data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                                '</td>';
                                        } else if (obj[i][tableArr[j]] == undefined) {
                                            tdStr += '<td rowspan="' + wjArr.length + '"></td>';
                                        } else {
                                            tdStr += '<td rowspan="' + wjArr.length + '">' + obj[i][tableArr[j]] + '</td>';
                                        }
                                    } else {
                                        if (tableArr[j] in wjArr[e]) {
                                            tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                        } else if (tableArr[j] == 'wj_accept') {
                                            //操作
                                            tdStr += '<td class="operation">' +
                                                '<span class="wj_accept" data-bb="' + k + '" data-index="' + e + '">接收</span>' +
                                                '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                                '<span class="wj_sh"  data-bb="' + k + '" data-index="' + e + '"  data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                                '</td>';
                                        }
                                    }
                                }
                                e == 0 ? (currentName == wjArr[e]['SHJG'] ? trStr += "<tr class='first' data-row='" + rowVal + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + rowVal + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (currentName == wjArr[e]['SHJG'] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                            }
                        }
                    }
                }
            }
        } else {
            //所登为上报机构?
            for (var m in uploadVal) {
                if (uploadVal[m] == currentName) {
                    tdStr = '';
                    var wjArr = obj[i].bb[m]['wj'],
                        wjBool = false;
                    wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                    if (wjBool) {
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                //单条文件?
                                if (e == 0) {
                                    if (tableArr[j] == 'XH') {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + xh + '</td>';
                                    } else if (tableArr[j] == 'BBMC') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="bbname">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'ZBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '" class="uploadorg">' + obj[i][tableArr[j]] + '</td>';
                                    } else if (tableArr[j] == 'SJSBJG') {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + uploadVal[m] + '</td>';
                                    } else if (tableArr[j] == 'bbstatus') {
                                        tdStr += '<td class="bbstatus" rowspan="' + wjArr.length + '">' + obj[i].bb[m].bbstatus + '</td>'
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_accept') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="wj_accept" data-bb="0" data-index="' + e + '">接收</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_sh" data-bb="0" data-index="' + e + '" data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjArr.length + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjArr.length + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'wjstatus' ? tdStr += '<td class="wjstatus">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_accept') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            '<span class="wj_accept" data-bb="0" data-index="' + e + '">接收</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '<span class="wj_sh" data-bb="0" data-index="' + e + '" data-toggle="modal" data-target="#myModalgh">审核</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == 0 ? (wjArr[e]['SHJG'] == currentName ? trStr += "<tr class='first' data-row='" + wjArr.length + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden first' data-row='" + wjArr.length + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>") : (wjArr[e]['SHJG'] == currentName ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr class='forbidden' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>");
                        }
                    }
                }
            }
        }
    }
    $('#bbAcceptTable>tbody').empty().append(trStr);
    var totalPage = Math.ceil(totalNum / everyNum);  //总页数
    var everyPage = obj.length;   //当前页条数
    $('.inputsTyle').eq(1).val(totalPage);
    $('.inputsTyle').eq(2).val(everyPage);
    $('.inputsTyle').eq(4).val(totalNum);
}

//省级数据上报及查询管理表格
function bbSearchTable(obj, currentPage, everyNumber) {
    var trStr = "",
        tableArr = getThead()[1],
        currentName = devisionc[localStorage.getItem('division_code')] + '-' + localStorage.getItem('career');
    for (var i = 0; i < obj.length; i++) {
        var tdStr = "",
            bbArr = obj[i]["bb"];
        var uploadVal = obj[i]['SJSBJG'].split(';');
        var xh = (parseInt(currentPage - 1) * 10) + i - 0 + 1;
        //省局及以上单位?
        if (localStorage.getItem('division_code') == '330000') {
            for (var k = 0; k < bbArr.length; k++) {
                //文件是否存在
                var currentK = [];
                var bbBool = false;
                bbBool = bbArr[k]["wj"] == undefined ? false : (bbArr[k]["wj"].length == 0 ? false : true);
                if (bbBool) {
                    if (uploadVal.length == 1) {
                        //单个数据上报机构
                        var wjArr = obj[i].bb[0]["wj"];
                        var wjLength = 0;
                        // 审核通过文件长度
                        for (var j in wjArr) {
                            if (wjArr[j]['wjstatus'] == '审核通过' || wjArr[j]['wjstatus'] == '审核不通过') wjLength += 1;
                        }
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                if (e == 0) {
                                    //单条上报文件
                                    if (tableArr[j] == 'XH') {
                                        tdStr += '<td rowspan="' + wjLength + '">' + xh + '</td>';
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_search') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            // '<span class="wj_sup" data-bb="0" data-index="' + e + '">上报</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjLength + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    //多条上报文件
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_search') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            // '<span class="wj_sup" data-bb="0" data-index="' + e + '">上报</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == 0 ? trStr += "<tr class='first' data-row='" + wjLength + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
                        }
                    } else {
                        //多个数据上报机构
                        //获取rowspan的值
                        var rowVal = 0;
                        for (var a in uploadVal) {
                            var wjArr = obj[i].bb[a]['wj'];
                            if (wjArr != undefined) {
                                if (wjArr.length) {
                                    for (var l = 0; l < wjArr.length; l++) {
                                        if (wjArr[l]['wjstatus'] == '审核通过' || wjArr[l]['wjstatus'] == '审核不通过') {
                                            rowVal += 1;
                                            currentK.push(a);
                                        }
                                    }
                                }
                            }
                        }
                        tdStr = '';
                        var wjBool = false;
                        var wjArr = bbArr[k]["wj"];
                        wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                        if (wjBool) {
                            var wjLength = 0;
                            var wjCurrent = [];
                            // 审核通过文件长度
                            for (var j in wjArr) {
                                if (wjArr[j]['wjstatus'] == '审核通过') {
                                    wjLength += 1;
                                    wjCurrent.push(j);
                                }
                            }
                            for (var e in wjArr) {
                                tdStr = '';
                                for (var j = 0, len = tableArr.length; j < len; j++) {
                                    if (e == wjCurrent[0]) {
                                        if (tableArr[j] == 'XH') {
                                            if (k == currentK[0]) {
                                                tdStr += '<td rowspan="' + rowVal + '">' + xh + '</td>';
                                            }
                                        } else if (tableArr[j] == 'SJSBJG') {
                                            tdStr += '<td rowspan="' + wjLength + '">' + bbArr[k]["title"] + '</td>';
                                        } else if (tableArr[j] in wjArr[e]) {
                                            tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                        } else if (tableArr[j] == 'wj_search') {
                                            //操作
                                            tdStr += '<td class="operation">' +
                                                // '<span class="wj_sup" data-bb="' + k + '" data-index="' + e + '">上报</span>' +
                                                '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                                '</td>';
                                        } else if (obj[i][tableArr[j]] == undefined) {
                                            tdStr += '<td rowspan="' + wjLength + '"></td>';
                                        } else {
                                            tdStr += '<td rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                        }
                                    } else {
                                        if (tableArr[j] in wjArr[e]) {
                                            tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                        } else if (tableArr[j] == 'wj_search') {
                                            //操作
                                            tdStr += '<td class="operation">' +
                                                // '<span class="wj_sup" data-bb="' + k + '" data-index="' + e + '">上报</span>' +
                                                '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                                '</td>';
                                        }
                                    }
                                }
                                e == wjCurrent[0] ? trStr += "<tr  class='first' data-row='" + rowVal + "' data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>" : trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";
                            }
                        }
                    }
                }
            }
        } else {
            for (var k in uploadVal) {
                if (currentName == uploadVal[k]) {
                    var wjArr = obj[i].bb[k]['wj'],
                        wjBool = false;
                    wjBool = wjArr == undefined ? false : (wjArr.length == 0 ? false : true);
                    if (wjBool) {
                        //审核通过?
                        var wjLength = 0,
                            wjCurrent = [];
                        // 审核通过文件长度
                        for (var j in wjArr) {
                            if (wjArr[j]['wjstatus'] == '审核通过') {
                                wjLength += 1;
                                wjCurrent.push(j);
                            }
                        }
                        for (var e in wjArr) {
                            tdStr = '';
                            for (var j = 0, len = tableArr.length; j < len; j++) {
                                if (e == wjCurrent[0]) {
                                    if (tableArr[j] == 'XH') {
                                        tdStr += '<td rowspan="' + wjLength + '">' + xh + '</td>';
                                    } else if (tableArr[j] == 'SJSBJG') {
                                        tdStr += '<td rowspan="' + wjLength + '">' + bbArr[k]["title"] + '</td>';
                                    } else if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_search') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            // '<span class="wj_sup" data-bb="' + k + '" data-index="' + e + '">上报</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '</td>';
                                    } else if (obj[i][tableArr[j]] == undefined) {
                                        tdStr += '<td rowspan="' + wjLength + '"></td>';
                                    } else {
                                        tdStr += '<td rowspan="' + wjLength + '">' + obj[i][tableArr[j]] + '</td>';
                                    }
                                } else {
                                    if (tableArr[j] in wjArr[e]) {
                                        tableArr[j] == 'WJMC' ? tdStr += '<td class="wj_name">' + wjArr[e][tableArr[j]] + '</td>' : (tableArr[j] == 'bstatus' ? tdStr += '<td class="bstatus">' + wjArr[e][tableArr[j]] + '</td>' : tdStr += '<td>' + wjArr[e][tableArr[j]] + '</td>');
                                    } else if (tableArr[j] == 'wj_search') {
                                        //操作
                                        tdStr += '<td class="operation">' +
                                            // '<span class="wj_sup" data-bb="' + k + '" data-index="' + e + '">上报</span>' +
                                            '<span class="op-download" data-id="' + wjArr[e]['sbid'] + '" data-url="' + wjArr[e]['sburl'] + '">下载</span>' +
                                            '</td>';
                                    }
                                }
                            }
                            e == wjCurrent[0] ? trStr += "<tr data-id='" + obj[i]['identifier'] + "'><td rowspan='" + wjLength + "'><input type='checkbox'></td>" + tdStr + "</tr>" : trStr += "<tr data-id='" + obj[i]['identifier'] + "'>" + tdStr + "</tr>";

                        }
                    }
                }
            }
        }
    }
    $('#bbSearchTable>tbody').empty().append(trStr);
    var totalPage = Math.ceil(totalNum / everyNum);  //总页数
    var everyPage = obj.length;   //当前页条数
    $('.inputsTyle').eq(1).val(totalPage);
    $('.inputsTyle').eq(2).val(everyPage);
    $('.inputsTyle').eq(4).val(totalNum);
}


//报表接收or文件接收or文件上报status改变
function bbAccept(buttonType, that) {
    var trActive = that.parent().parent(),
        projectId = trActive.attr('data-id'),
        bbIndex = '',
        wjIndex = '',
        txt = '';
    switch (buttonType) {
        case '接收报表':
            bbIndex = that.attr('data-index');
            txt = trActive.find('.bbname').html();
            break;
        case '接收文件':
        case '上报文件':
            bbIndex = that.attr('data-bb');
            wjIndex = that.attr('data-index');
            txt = trActive.find('.wj_name').html();
            break;
    }
    if (trActive.hasClass('forbidden')) {
        alertMs('你没有操作' + txt + '的权限');
        return false;
    } else {
        if (buttonType == '接收报表' && trActive.find('.bbstatus').html() != '未接收') {
            alertMs('只能对未接收的报表进行接收');
            return false;
        } else if (buttonType == '接收文件' && trActive.find('.wjstatus').html() != '未接收') {
            alertMs('只能对未接收的文件进行接收');
            return false;
        } else if (buttonType == '上报文件' && trActive.find('.bstatus').html() != '未上报部') {
            alertMs('只能对未上报部的文件进行上报');
            return false;
        } else {
            var addData = {};
            var add = {
                "content": {}
            }
            for (var i = 0; i < data.length; i++) {
                if (data[i].identifier == projectId) {
                    for (var c in data[i]) {
                        switch (c) {
                            case "identifier":
                            case "to_career":
                            case "to_division":
                            case "modified":
                            case "project_type":
                            case "category":
                            case "user_name":
                            case "trial_first":
                            case "trial_forth":
                            case "trial_second":
                            case "trial_third":
                            case "status":
                                add[c] = data[i][c];
                                break;
                            case 'history':
                                add[c] = '';
                            default:
                                addData[c] = data[i][c];
                                break;
                        }
                    }
                }
            }
            add.content = $.extend({}, add.content, addData);
            alertMs(buttonType + '：' + txt + '', 2, function () {
                switch (buttonType) {
                    case '接收报表':
                        add.content.bb[bbIndex]["bbstatus"] = '已接收未上报';
                        break;
                    case '接收文件':
                        add.content.bb[bbIndex]["wj"][wjIndex]['wjstatus'] = '审核中';
                        break;
                    case '上报文件':
                        add.content.bb[bbIndex]["wj"][wjIndex]['bstatus'] = '部审核中';
                        break;
                }
                var datan = JSON.stringify(add);
                $.ajax({
                    type: 'post',
                    url: '/api/update_project?project_id=' + projectId,
                    data: datan,
                    success: function (result) {
                        location.reload();
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
            })
        }
    }
}

//上报数据变化
function upChange(buttonType, that, bbIndex, wjIndex) {
    //buttonType: 按钮类型  that：当前点击的$(this)  bbIndex：bb报表的index  wjIndex：bb中wj的index
    var trActive = that.parent().parent(),
        projectId = trActive.attr('data-id');
    var addData = {},
        add = { "content": {} },
        docData = {},
        docArr = [];
    for (var i = 0; i < data.length; i++) {
        if (data[i].identifier == projectId) {
            for (var c in data[i]) {
                switch (c) {
                    case "identifier":
                    case "to_career":
                    case "to_division":
                    case "modified":
                    case "project_type":
                    case "category":
                    case "user_name":
                    case "trial_first":
                    case "trial_forth":
                    case "trial_second":
                    case "trial_third":
                    case "status":
                        add[c] = data[i][c];
                        break;
                    case "history":
                        add[c] = '';
                        break;
                    default:
                        addData[c] = data[i][c];
                        break;
                }
            }
        }
    }
    var txt = '';
    switch (buttonType) {
        case "上报":
            addData.bb[bbIndex]["bbstatus"] = '已上报';
            docData["wjstatus"] = '未接收';
            docData["SBJG"] = devisionc[localStorage.getItem('division_code')] + '-' + localStorage.getItem('career');
            //获取上报文件
            $('.tabContainer').find('.data-get').each(function () {
                var className = $(this).attr('data-name');
                if ($('.' + className).hasClass('input') || $('.' + className).hasClass('textarea')) {
                    if (className == 'SBWJ') {
                        docData['sbid'] = $('.' + className).attr('data-id');
                        docData['sburl'] = $('.' + className).attr('data-url');
                    } else {
                        if (className == 'WJMC') sbName = $('.' + className).val();
                        docData[className] = $('.' + className).val();
                    }
                } else if ($('.' + className).hasClass("select")) {
                    docData[className] = $('.' + className).html();
                }
            });
            add.content = $.extend({}, add.content, addData);
            var bb = add.content.bb;
            docArr.push(docData);
            bb[bbIndex]["wj"] = bb[bbIndex]["wj"] == undefined ? docArr : bb[bbIndex]["wj"].concat(docArr);
            txt = trActive.find('.bbname').html();
            break;
        case '删除':
            add.content = $.extend({}, add.content, addData);
            add.content.bb[bbIndex]["wj"].splice(wjIndex, 1);
            txt = trActive.find('.wj_name').html();
            break;
        case '审核':
            add.content = $.extend({}, add.content, addData);
            add.content.bb[bbIndex]["wj"][wjIndex]["SHYJ"] = $('.SHYJ').val();
            add.content.bb[bbIndex]['wj'][wjIndex]['wjstatus'] = $('input:radio[name="shresult"]:checked').val();
            add.content.bb[bbIndex]["wj"][wjIndex]['bstatus'] = '审核通过';
            break;
    }
    if (!$('.tabContainer').hasClass('sjContainer')) $.contentCheck();
    if (buttonType == '删除' && trActive.find('.wjstatus').html() != '未接收') {
        alertMs('只能删除未接收的文件');
        return false;
    } else {
        if (buttonType == '删除') {
            alertMs(buttonType + '文件：' + txt, 2, function () {
                var wj = add.content.bb[bbIndex]["wj"];
                if (wj.length == 0) add.content.bb[bbIndex]['bbstatus'] = '已接收未上报';
                var datan = JSON.stringify(add);
                $.ajax({
                    type: 'post',
                    url: '/api/update_project?project_id=' + projectId,
                    data: datan,
                    success: function (result) {
                        location.reload();
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
            })
        } else {
            if (buttonType == '审核' && $('input:radio[name="shresult"]:checked').val() == undefined) {
                alertMs('请选择审核结果');
            } else {
                var datan = JSON.stringify(add);
                $.ajax({
                    type: 'post',
                    url: '/api/update_project?project_id=' + projectId,
                    data: datan,
                    success: function (result) {
                        alertMs(buttonType + '已完成', 1, function () {
                            location.reload();
                        })
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
            }
        }
    }
}


//省级投资校验获取合计val
function getVal(that) {
    var Val = [], //Val = ['name','class','value']
        dataName = $(that).attr('data-name'),
        name = $(that).prev().html().slice(0, -1);
    if ($('.' + dataName).hasClass('input') || $('.' + dataName).hasClass('textarea')) {
        Val = [name, dataName, $('.' + dataName).val()];
    } else if ($('.' + dataName).hasClass('select')) {
        if ($('.' + dataName).hasClass('selectpicker')) {
            Val = $('.' + dataName)[1].innerText.indexOf('请选择') == -1 ? [name, dataName, $('.' + dataName)[1].innerText] : [name, dataName, ''];
        } else {
            Val = [name, dataName, $('.' + dataName + ' option:selected').html()];
        }
    }
    return Val;
}

//省级投资校验
function sjCheck(buttonType, projectId) {
    var red = [],
        point = [],
        jshj = [],
        jyhj = [],
        stxj = [],
        xmbmArr = [];
    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    //去除之前的checkErr
    $('.data-get').children().removeClass('checkErr');
    $('#ghxzModal .modal-body').each(function (index, item) {
        $(this).children().find('.data-get').each(function () {
            that = this;
            if ($(that).prev().hasClass('color-red')) {
                red.push(getVal(that));
            }
        });
        $(this).children().find('.point').each(function () {
            var that = this;
            point.push(getVal(that));
        })
        $(this).children().find('.jsxj').each(function () {
            var that = this;
            $(that).children().find('.data-get').each(function (index, item) {
                jshj.push(getVal(item));
            });
        });
        $(this).children().find('.jyhj').each(function () {
            var that = this;
            $(that).children().find('.data-get').each(function (index, item) {
                jyhj.push(getVal(item));
            });
        });
        $(this).children().find('.stxj').each(function () {
            var that = this;
            $(that).children().find('.data-get').each(function (index, item) {
                stxj.push(getVal(item));
            });
        })
    });
    var redCount = 0;
    //必填字段是否为空
    $.each(red, function (i, val) {
        redCount++;
        if (val[2] == '') {
            $('.' + val[1]).addClass('checkErr');
            alertMs(val[0] + "不能为空", 1, function () {
                scrollAnimate();
            });
            return false;
        }
    });
    //顺序码是否存在
    for (var i = 0; i < data.length; i++) {
        if (buttonType == 'xg') {
            data[i]['identifier'] != projectId && xmbmArr.push(data[i]['SJ_JBXX']['XMBM']);
        } else {
            xmbmArr.push(data[i]['SJ_JBXX']['XMBM']);
        }
    }

    var pointCount = 0;
    if (redCount == red.length && redCount != 0) {
        var xmbmBool = false;
        if ($.inArray($('.XMBM-auto').val(), xmbmArr) != -1) {
            $('.MSXM,.ZSXM').addClass('checkErr');
            alertMs('此顺序码已存在', 1, function () {
                scrollAnimate();
                return false;
            })
        } else {
            xmbmBool = true;
        }
        //数值验证
        if (xmbmBool) {
            $.each(point, function (i, val) {
                pointCount++;
                if (val[2] != '' && !val[2].match(/^\d+(\.\d{1,3})?$/)) {
                    $('.' + val[1]).addClass('checkErr');
                    alertMs(val[0] + "最多可精确到小数点后3位", 1, function () {
                        scrollAnimate();
                    });
                    return false;
                }
            });
        }
    }

    if (pointCount == point.length && pointCount != 0) {
        //建设规模合计
        var jsVal = 0;
        $.each(jshj, function (i, val) {
            if (val[2] != '') jsVal += (val[2] - 0);
        });
        //2018年建议计划合计
        var jyVal = 0;
        $.each(jyhj, function (i, val) {
            if (val[2] != '') jyVal += (val[2] - 0);
        });
        if (!!$('.JSHJ').val() && jsVal != ($('.JSHJ').val() - 0)) {
            $('.JSHJ').addClass('checkErr');
            alertMs("建设总里程数合计必须等于支线/连接线+主线里程数", 1, function () {
                scrollAnimate();
            });
            return false;
        }
        if (!!$('.HJ').val()) {
            var title = '';
            switch (type) {
                case 'sjjc': case 'jtjc':
                    title = '2018年投资合计必须等于民航基金+地方政府投资+社会投资+银行贷款+企业投资+其他资金';
                    break;
                case 'sjtz':
                    title = '2018年投资合计必须等于中央投资+省投资+其他投资';
                    break;
                default:
                    title = '2018年投资合计必须等于中央投资+省投资+省厅投资+其他投资';
                    break;
            }
            if (!!$('.STXJ').val()) {
                if ((jyVal - ($('.STXJ').val() - 0)) != ($('.HJ').val() - 0)) {
                    $('.HJ').addClass('checkErr');
                    alertMs(title, 1, function () {
                        scrollAnimate();
                    });
                    return false;
                }
            } else {
                if (jyVal != ($('.HJ').val() - 0)) {
                    $('.HJ').addClass('checkErr');
                    alertMs(title, 1, function () {
                        scrollAnimate();
                    });
                    return false;
                }
            }
        }
        //省厅投资合计
        var sttzVal = 0;
        if (stxj.length) {
            var lastVal = (stxj[stxj.length - 1][2] - 0);
            $.each(stxj, function (i, val) {
                if (val[2] != '') sttzVal += (val[2] - 0);
            });
            if ($('.STXJ').val() != '' && (sttzVal - lastVal) != ($('.STXJ').val() - 0)) {
                $('.STXJ').addClass('checkErr');
                alertMs("省厅投资合计必须等于燃油税+一般预算范围内+地方政府债券+省基础设施投资基金+通行费", 1, function () {
                    scrollAnimate();
                });
                return false;
            }
        }
        if (localStorage.getItem('acId') == 'road_combine' && $('#ghxzModal .confirmBtn').eq(0).attr('data-type') != 'addNew' && $('#ghxzModal .confirmBtn').eq(1).attr('data-type') != 'editNew') itemCheck();
    }

}

function scrollAnimate() {
    var winHeight = window.innerHeight,
        scrollTop = $('html', window.top.document).scrollTop(),
        checkTop = -$('.checkErr').offset().top,
        modalHeight = $('.modal1 .tabContainer').height(),
        confirmHeight = $('#ghxzModal .confirmBtn')[0].offsetTop;
    $('.modal1.in').animate({ scrollTop: modalHeight - checkTop - winHeight - 35 - 34 }, 1000);
    $('html', window.top.document).animate({ scrollTop: 0 }, 1000);
}

// 子母项目总和验证
function itemCheck() {
    var all = addItemArr.concat(selectItemArr);  //selected items‘s data
    $('#ghxzModal .modal-body').each(function () {
        $(this).children().find('.data-get').each(function () {
            var title = $(this).prev().html(),
                dataName = $(this).attr('data-name');
            if (/(万|里程|合计|米|人次|长度)/.test(title)) {
                var total = $('.' + dataName).val(),
                    addVal = 0;
                for (var i = 0; i < all.length; i++) {
                    var content = all[i]['content'];
                    for (var j in content) {
                        if (content[j] instanceof Object) {
                            if (content[j].hasOwnProperty(dataName)) {
                                var value = content[j][dataName] == '' ? 0 : content[j][dataName];
                                addVal = addVal + (value - 0);
                            }
                        }
                    }
                }
                total == '' ? 0 : total;
                if ((total - 0) != addVal) {
                    $(this).children().addClass('checkErr');
                    alertMs(title.substr(0, title.length - 1) + '不等于所有子项目的总和', 1, function () {
                        scrollAnimate();
                    });
                    return false;
                } else {
                    $(this).children().removeClass('checkErr');
                }
            }
        });
        if ($('#ghxzModal .checkErr').length) return false;
    });
}

function selectPeople(id) {
    var peopleArr = [];
    for (var i in data) {
        if (data[i]["user_name"] == id) {
            peopleArr = data[i]['binders'];
        }
    }
    $('.bind-people').on('click', function () {
        var current = $('.bind').val();
        if ($.inArray(current, peopleArr) == -1 && current != '') {
            peopleArr.push(current);
            var peopleHtml = '<div class="people"><span>' + current + '</span><span class="close-people">X</span></div>';
            $('.new-people').append(peopleHtml);
            $('.bind').val('');
        } else {
            alertMs('该人员已存在，请重新输入');
            $('.bind').val('');
        }
    });
    $('body').on('click', '.close-people', function () {
        var close = $(this).prev().html();
        $(this).parent().remove();
        peopleArr.splice(peopleArr.indexOf(close), 1);
    });
}

//用户列表
function userTable(obj, currentPage, everyNumber) {
    var trStr = "",
        tableArr = getThead()[1];
    for (var i = 0; i < data.length; i++) {
        var tdStr = '';
        var xh = (parseInt(currentPage - 1) * 10) + i - 0 + 1;
        for (var j = 0; j < tableArr.length; j++) {
            if (tableArr[j] == 'XH') {
                tdStr += '<td>' + xh + '</td>';
            } else if (tableArr[j] == 'binders') {
                if (data[i]["binders"].length == 0) {
                    tdStr += '<td></td>';
                } else {
                    var binder = '';
                    for (var a = 0; a < data[i]["binders"].length; a++) {
                        binder += data[i]["binders"][a] + ',';
                    }
                    tdStr += '<td>' + binder.substring(0, binder.length - 1) + '</td>';
                }
            } else if (tableArr[j] == 'trial_first' || tableArr[j] == 'trial_second' || tableArr[j] == 'trial_third' || tableArr[j] == 'trial_forth') {
                if (data[i][tableArr[j]] == 0) {
                    tdStr += '<td>否</td>';
                } else {
                    tdStr += '<td>是</td>';
                }
            } else if (tableArr[j] == 'career') {
                if (data[i]["division_code"] == '') {
                    tdStr += '<td></td>';
                } else {
                    var code = devisionc[data[i]["division_code"]],
                        codeArr = code.split('-');
                    if (codeArr.length > 2) {
                        tdStr += '<td>' + codeArr[0] + '-' + codeArr[1] + '-' + codeArr[2] + data[i]['career'] + '</td>';
                    } else {
                        tdStr += '<td>' + code + '-' + data[i]['career'] + '</td>';
                    }
                }
            } else if (tableArr[j] == 'right') {
                data[i]["right"] == 1 ? tdStr += '<td>是</td>' : tdStr += '<td>否</td>';
            } else {
                tdStr += '<td>' + data[i][tableArr[j]] + '</td>';
            }
        }
        trStr += '<tr data-id="' + data[i]["user_name"] + '">' + tdStr + '</tr>';
    }
    $('#userTable tbody').empty().append(trStr);
    $('.data-table').fixTable(4);
    var totalPage = Math.ceil(totalNum / everyNum);  //总页数
    var everyPage = obj.length;   //当前页条数
    $('.inputsTyle').eq(1).val(totalPage);
    $('.inputsTyle').eq(2).val(everyPage);
    $('.inputsTyle').eq(4).val(totalNum);
}

//用户新增
function newPeople() {
    var binders = [],
        peopleObj = {};
    $('.new-people .people').each(function (j) {
        binders.push($(this).find('span').eq(0).html());
    });
    peopleObj["binders"] = binders;
    peopleObj["status"] = binders.length == 0 ? "未绑定" : "已绑定";
    $('#ghxzModal').find('.data-get').each(function (i) {
        var dataName = $(this).attr('data-name');
        if ($('#ghxzModal .' + dataName).hasClass('input')) {
            if (dataName == 'industry') {
                peopleObj["division_code"] = $('#ghxzModal .' + dataName).attr('data-code');
                peopleObj["career"] = $('#ghxzModal .' + dataName).attr('data-career');
            } else {
                peopleObj[dataName] = $('#ghxzModal .' + dataName).val();
            }
        } else {
            if (dataName == 'modal_right') {
                var selectOption = $('.filter-option').html();
                peopleObj[dataName] = selectOption == '请选择' ? '' : selectOption.replace(/(五年规划)/, 'wn').replace(/( 部级投资计划)/, 'jy').replace(/( 省级政府投资计划)/, 'sj').replace(/( 全省交通建设计划)/, 'jt').replace(/( 农村公路)/, 'nc').replace(/(全部)/, 'all');
            } else {
                peopleObj[dataName] = $('#ghxzModal .' + dataName + ' option:selected').val();
            }
        }
    });
    return peopleObj;
}

//用户赋值
function editPeople(id) {
    for (var i in data) {
        if (data[i]["user_name"] == id) {
            $('#ghxzModal').find('.data-get').each(function (j) {
                var dataName = $(this).attr('data-name');
                $('#ghxzModal .' + dataName).val(data[i][dataName]);
                if (dataName == 'industry') {
                    if (data[i]["division_code"] == '') {
                        $('#ghxzModal .' + dataName).val('');
                    } else {
                        var code = devisionc[data[i]["division_code"]],
                            codeArr = code.split('-');
                        if (codeArr.length > 2) {
                            $('#ghxzModal .' + dataName).val(codeArr[0] + '-' + codeArr[1] + '-' + codeArr[2] + data[i]['career']);
                        } else {
                            $('#ghxzModal .' + dataName).val(code + '-' + data[i]['career']);
                        }
                    }
                    $('#ghxzModal .' + dataName).attr('data-code', data[i]["division_code"]);
                    $('#ghxzModal .' + dataName).attr('data-career', data[i]["career"]);
                } else if (dataName == 'right') {
                    data[i]["right"] == 1 ? $('#ghxzModal .' + dataName).val("1") : $('#ghxzModal .' + dataName).val("0");
                } else if (dataName == 'modal_right') {
                    $('.dropdown-menu.selectpicker').find('li').removeClass('selected');
                    var array = data[i][dataName].split(',');
                    $('.modal_right').selectpicker('val', array);
                    for (var j = 0; j < array.length; j++) {
                        switch (array[j]) {
                            case 'wn':
                                $('.dropdown-menu.selectpicker').find('li').eq(1).addClass('selected');
                                break;
                            case 'jy':
                                $('.dropdown-menu.selectpicker').find('li').eq(2).addClass('selected');
                                break;
                            case 'sj':
                                $('.dropdown-menu.selectpicker').find('li').eq(3).addClass('selected');
                                break;
                            case 'jt':
                                $('.dropdown-menu.selectpicker').find('li').eq(4).addClass('selected');
                                break;
                            case 'nc':
                                $('.dropdown-menu.selectpicker').find('li').eq(5).addClass('selected');
                                break;
                            case 'all':
                                $('.dropdown-menu.selectpicker').find('li').eq(0).addClass('selected');
                                break;
                            default:
                                break;
                        }
                    }
                }
            });
            var bindArr = data[i]["binders"],
                peopleHtml = '';
            for (var j = 0; j < bindArr.length; j++) {
                peopleHtml += '<div class="people"><span>' + bindArr[j] + '</span><span class="close-people">X</span></div>';
            }
            $('.new-people').empty().append(peopleHtml);
        }
    }
}

//XZQH && XZQHMC
function getxzqhCode(className) {
    var code = '',
        name = '';
    var provinceCode = $('.' + className + ' .xzqh-province option:selected').val(),
        province = $('.' + className + ' .xzqh-province option:selected').html(),
        cityCode = $('.' + className + ' .xzqh-city option:selected').val(),
        city = $('.' + className + ' .xzqh-city option:selected').html(),
        areaCode = $('.' + className + ' .xzqh-area option:selected').val(),
        area = $('.' + className + ' .xzqh-area option:selected').html();
    if (cityCode == '' && areaCode == '') {
        //省
        code = provinceCode;
        name = province;
    } else if (areaCode == '') {
        // 省市
        code = cityCode;
        name = province + city;
    } else {
        //省市区
        code = areaCode;
        name = province + city + area;
    }
    return [code, name];
}

// 农村公路字段检验
function ncCheck(buttonType, projectId) {
    var xmCode = [],
        kyCode = [];
    //去除之前的checkErr
    $('.data-get').children().removeClass('checkErr');

    for (var i = 0; i < data.length; i++) {
        if (!!data[i]['TABLE_XMJBXX']) {
            if (buttonType == 'xg') {
                data[i]['identifier'] != projectId && xmCode.push(data[i]['TABLE_XMJBXX']['XMBM']);
            } else {
                xmCode.push(data[i]['TABLE_XMJBXX']['XMBM']);
            }
        } else if (!!data[i]['TABLE_KYZJSGM']) {
            if (buttonType == 'xg') {
                data[i]['identifier'] != projectId && kyCode.push(data[i]['TABLE_KYZJSGM']['KYZBM']);
            } else {
                kyCode.push(data[i]['TABLE_KYZJSGM']['KYZBM']);
            }
        }
    }
    if (!$('.bodyObj').hasClass('none')) {
        var boolObj = true;
        $('.bodyObj:not(.none)').each(function () {
            if (boolObj) {
                $(this).find('.data-get').each(function () {
                    var className = $(this).attr('data-name');
                    //必填项
                    var name = $(this).prev().html();
                    if ($(this).prev().hasClass('color-red')) {
                        if ($('.' + className).hasClass('input')) {
                            if ($('.' + className).val() == '') {
                                $('.' + className).addClass('checkErr');
                                alertMs(name.substring(0, name.length - 1) + '不能为空', function () {
                                    scrollAnimate();
                                });
                                boolObj = false;
                                return false;
                            } else {
                                $('.' + className).removeClass('checkErr');
                            }
                        } else if ($('.' + className).hasClass('select')) {
                            if (className == 'XZQHMC') {
                                if ($('.' + className + ' .xzqh-province option:selected').val() == '') {
                                    $('.' + className + ' .xzqh-province').addClass('checkErr');
                                    alertMs(name.substring(0, name.length - 1) + '不能为空', function () {
                                        scrollAnimate();
                                    });
                                    boolObj = false;
                                    return false;
                                } else {
                                    $('.' + className + ' .xzqh-province').removeClass('checkErr');
                                }
                            } else {
                                if ($('.' + className + ' option:selected').html() == '') {
                                    $('.' + className).addClass('checkErr');
                                    alertMs(name.substring(0, name.length - 1) + '不能为空', function () {
                                        scrollAnimate();
                                    });
                                    boolObj = false;
                                    return false;
                                } else {
                                    $('.' + className).removeClass('checkErr');
                                }
                            }
                        }
                    }
                    // 小数点后3位
                    if (/(万元|万吨|万人次|公里|米|延米|里程:)/.test(name)) {
                        var value = $('.' + className).val();
                        if (!/^\d+(\.\d{1,3})?$/.test(value) && value != '') {
                            $('.' + className).addClass('checkErr');
                            alertMs(name.substring(0, name.length - 1) + '最多可精确到小数点后3位', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (value != '0' && value.split('.')[1] == undefined && /^0+/.test(value.split('.')[0])) {
                            $('.' + className).addClass('checkErr');
                            alertMs(name.substring(0, name.length - 1) + '不能以0开头', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    }
                    // 整数
                    if (/(\(处|\(个|\(座)/.test(name)) {
                        if (!/^(\d)+$/g.test($('.' + className).val()) && $('.' + className).val() != '') {
                            $('.' + className).addClass('checkErr');
                            alertMs(name.substring(0, name.length - 1) + '为非负整数', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    }
                    if (className == 'XMBM') {
                        //项目唯一编码
                        var XMBM = $('.XMBM').val();
                        if (!/\d{13}/.test(XMBM)) {
                            $('.' + className).addClass('checkErr');
                            alertMs('项目唯一编码必须由13位数字组成', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (XMBM.substring(0, 4) != $('.JHNF').val()) {
                            $('.' + className).addClass('checkErr');
                            alertMs('项目唯一编码前4位与计划年份不一致', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (XMBM.substring(4, 10) != getxzqhCode('XZQHMC')[0]) {
                            $('.' + className).addClass('checkErr');
                            alertMs('项目唯一编码第5位至第10位与计划项目所在县的行政区划代码不一致', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if ($.inArray(XMBM, xmCode) != -1) {
                            $('.' + className).addClass('checkErr');
                            alertMs('此项目唯一编码后3位顺序码已存在', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'TBDWDM') {
                        //填报单位代码
                        if ($('.' + className).val().length != 9) {
                            $('.' + className).addClass('checkErr');
                            alertMs('填报单位代码为9位', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'JSWGN') {
                        // 建设完工年必须大于建设开工年
                        if (parseInt($('.JSWGN').val()) < parseInt($('.JSKGN').val())) {
                            $('.' + className).addClass('checkErr');
                            alertMs('建设完工年必须大于建设开工年', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'SFFNDAPJH') {
                        // 是否按年度安排
                        var JSKGN = $('.JSKGN').val(),
                            JSWGN = $('.JSWGN').val(),
                            SFFNDAPJH = $('.SFFNDAPJH option:selected').html();
                        if (JSKGN == JSWGN && SFFNDAPJH != '否') {
                            $('.' + className).addClass('checkErr');
                            alertMs('开工年和完工年相等时是否按年度安排为否', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (JSKGN != JSWGN && SFFNDAPJH != '是') {
                            $('.' + className).addClass('checkErr');
                            alertMs('开工年和完工年不相等时是否按年度安排为是', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'NDJHZE') {
                        // 年度合计
                        var total = parseFloat($('.NDJHZE').val()),
                            num1 = parseFloat($('.NDJHCGSTZ').val()),
                            num2 = parseFloat($('.NDJHDFTZ').val());
                        if (total.toFixed(3) != (num1 + num2).toFixed(3)) {
                            $('.' + className).addClass('checkErr');
                            alertMs('年度计划投资合计 = 年度计划车购税投资 + 年度计划地方投资', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'LXBM') {
                        // 路线编码
                        var LXBM = $(this).find('.input').val();
                        if (LXBM.length != 10) {
                            $(this).children().addClass('checkErr');
                            alertMs('路线编码位数为10位', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (/[a-z]/.test(LXBM.substring(0, 4))) {
                            $(this).children().addClass('checkErr');
                            alertMs('路线编码前四位如果有英文必须要大写', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (LXBM.substring(4, 10) != getxzqhCode('XZQHMC')[0]) {
                            $(this).children().addClass('checkErr');
                            alertMs('路线编码最后6位与行政区划代码相等', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $(this).children().removeClass('checkErr');
                        }
                    } else if (className == 'ZDZH') {
                        // 迄点桩号(公里)不能小于起点桩号(公里)
                        var ZDZH = parseFloat($('.ZDZH').val()),
                            QDZH = parseFloat($('.QDZH').val());
                        if (ZDZH.toFixed(3) - QDZH.toFixed(3) < 0) {
                            $('.' + className).addClass('checkErr');
                            if ($('.JHJSLC').length) {
                                alertMs('迄点桩号(公里)必须大于起点桩号(公里)', function () {
                                    scrollAnimate();
                                });
                            } else {
                                alertMs('隐患路段迄点桩号(公里)必须大于隐患路段起点桩号(公里)', function () {
                                    scrollAnimate();
                                });
                            }
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'JHJSLC' && $('.JHJSLC').val() != '') {
                        // 计划建设里程
                        var JHJSLC = parseFloat($('.JHJSLC').val()),
                            reduce = ($('.ZDZH').val() - $('.QDZH').val()).toFixed(3),
                            one = reduce.match(/^\d+\.\d/),
                            oneMore = one - 0 + ('0.1' - 0);
                        if ((JHJSLC.toFixed(3) - one) < 0 || (JHJSLC.toFixed(3) - oneMore) > 0) {
                            $('.' + className).addClass('checkErr');
                            alertMs('计划建设里程(公里) = 迄点桩号(公里) - 起点桩号(公里)', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'KYZBM') {
                        // 客运站编码
                        var KYZBM = $('.KYZBM').val();
                        if (KYZBM.length != 15) {
                            $('.' + className).addClass('checkErr');
                            alertMs('客运站编码总共有15位', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (KYZBM.substring(0, 6) != getxzqhCode('XZQHMC')[0]) {
                            $('.' + className).addClass('checkErr');
                            alertMs('客运站编码前6位=行政划代码', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (KYZBM.substr(12, 1) != 'K') {
                            $('.' + className).addClass('checkErr');
                            alertMs('客运站编码倒数第3位必须是大写K', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if ($.inArray(KYZBM, kyCode) != -1) {
                            $('.' + className).addClass('checkErr');
                            alertMs('此客运站编码后2位顺序码已存在', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'YHLC' && $('.YHLC').val() != '') {
                        // 隐患里程(公里)
                        var YHLC = parseFloat($('.YHLC').val());
                        if (($('.ZDZH').val() - $('.QDZH').val()).toFixed(3) != YHLC.toFixed(3)) {
                            $('.' + className).addClass('checkErr');
                            alertMs('隐患里程(公里) = 隐患路段迄点桩号(公里) - 隐患路段起点桩号(公里)', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'JMDBM' && $('.JMDBM').val() != '') {
                        // 居民点编码
                        var JMDBM = $('.JMDBM').val();
                        if (!/^\d{15}$/.test(JMDBM)) {
                            $('.' + className).addClass('checkErr');
                            alertMs('居民点编码为15位数字', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (JMDBM.substring(0, 6) != getxzqhCode('XZQHMC')[0]) {
                            $('.' + className).addClass('checkErr');
                            alertMs('居民点编码前6位=行政区划代码', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'DKBM' && $('.DKBM').val() != '') {
                        // 渡口编码
                        var DKBM = $('.DKBM').val();
                        if (DKBM.length != 15) {
                            $('.' + className).addClass('checkErr');
                            alertMs('渡口编码为15位', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (DKBM.substring(4, 10) != getxzqhCode('XZQHMC')[0]) {
                            $('.' + className).addClass('checkErr');
                            alertMs('渡口编码第5位到第10位=行政区划代码', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else if (DKBM.substr(10, 1) != 'D') {
                            $('.' + className).addClass('checkErr');
                            alertMs('渡口编码倒数第5位为大写的D', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'QLBM' && $('.QLBM').val()) {
                        // 桥梁编码
                        var QLBM = $('.QLBM').val();
                        if (!/^\d{15}/.test(QLBM)) {
                            $('.' + className).addClass('checkErr');
                            alertMs('桥梁编码为15位数字', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    } else if (className == 'JHNF') {
                        //计划年份
                        if ($('.JHNF').val() > $('.JSKGN').val()) {
                            $('.' + className).addClass('checkErr');
                            alertMs('计划年份需不大于建设开工年', function () {
                                scrollAnimate();
                            });
                            boolObj = false;
                            return false;
                        } else {
                            $('.' + className).removeClass('checkErr');
                        }
                    }
                });
            }
        });
    }

}

//居民点无效
function areaInvalid() {
    $('.jmdInput').on('change', function () {
        var value = $('.jmdInput:checked').val();
        $('#ghxzModal .modal-body').each(function () {
            if ($(this).attr('data-body') == 'TABLE_JMDXX') {
                if (value == '有效') {
                    $(this).find('.data-get').each(function () {
                        var dataName = $(this).attr('data-name');
                        if (dataName == 'JMDLX' || dataName == 'JMDBM' || dataName == 'TDZK') {
                            $(this).prev().addClass('color-red');
                        }
                    })
                } else {
                    $(this).find('.color-red').each(function () {
                        $(this).removeClass('color-red');
                    })
                }
            }
        });
    })
}

//自动生成填报单位
function autoCode() {
    var dwCode = {
        "交通运输厅": '1',
        "交通运输局": '1',
        "公路局": '2',
        "运管局": '7',
        "港航局": '8',
        "港务(航)管理局": '8'
    };
    var career = localStorage.getItem('career'),
        division_code = localStorage.getItem('division_code'),
        code = '';
    if (division_code.substring(2, 6) == '0000') {
        // 省厅/省局
        code = division_code.substring(0, 2) + dwCode[career] + '000000';
    } else if (division_code.substring(4, 6) == '00') {
        //地市
        code = division_code.substring(0, 2) + dwCode[career] + division_code.substring(2, 4) + dwCode[career] + '000';
    } else {
        //县级
        code = division_code.substring(0, 2) + dwCode[career] + division_code.substring(2, 4) + dwCode[career] + division_code.substring(4, 6) + dwCode[career];
    }
    !!dwCode[career] && $('.TBDWDM').val(code);
    // 填报单位名称
    $('.TBDWMC').val(devisionc[localStorage.getItem('division_code')] + localStorage.getItem('career'));
}

//多表克隆
function editMuti(tableNum, tableName, tableWrap) {
    $(tableName + ':last').after($(tableName + ':first').clone(true));
    $(tableName + ':last').find('input').val("");
    $(tableWrap + '>h5:last').after($(tableWrap + '>h5:first').clone());
    $(tableWrap + '>h5:last').html($(tableWrap + '>h5').html() + tableNum);
    $(tableWrap + '>h5:last').addClass('h5Active').siblings().removeClass('h5Active');
    $(tableName + ':last').find('h5').eq(0).html($(tableWrap + '>h5').html() + tableNum);
    $(tableName + ':last').find('textarea').val("");
    $(tableName + ':last').find('select>option:selected').val("");
    $(tableName + ':last').slideDown().siblings(tableName).slideUp();
    $(tableName + ',' + tableWrap + '>h5').addClass('clone');
    $(tableName).eq(0).removeClass('clone');
    $(tableWrap + '>h5').eq(0).removeClass('clone');
}

//单表赋值
function editSigle(that, e, val, selectData) {
    if (!!that) {
        that.eq(e).find('.data-get').each(function (b) {
            var dataName = $(this).attr('data-name');
            if (that.eq(e).find('.' + dataName).hasClass("input") || $('.' + dataName).hasClass('textarea')) {
                if (dataName == 'XZQH') that.eq(e).find('.' + dataName).attr('data-vercode', val[e][dataName]);
                that.eq(e).find('.' + dataName).val(val[e][dataName]);
            } else if (that.eq(e).find('.' + dataName).hasClass("select")) {
                if (that.eq(e).find('.' + dataName).hasClass("multiple")) {
                    var array = val[e][dataName].split(',')
                    that.eq(e).find('.' + dataName).selectpicker('val', array);
                } else {
                    that.eq(e).find('.' + dataName).val(val[e][dataName]);
                }
            }
        })
    }
}

//修改
function editMatch(projectId, txt, allData) {
    $('.kzd-table tbody').empty();
    if (pline) {
        maplet.removeOverlay(pline);
        pline = null;
    }
    if (kzdPlineArr.length) {
        for (var a in kzdPlineArr) {
            maplet.removeOverlay(kzdPlineArr[a]);
        }
        kzdPlineArr = [];
    }
    sessionStorage.removeItem('mapArray');
    selectItemArr = [];
    $('#ghxzModal').find('input').attr('readonly', false);
    $('#ghxzModal').find('select, textarea').attr('disabled', false);
    $('.XMBM-auto').attr('readonly', true);
    var provinceArr = ['交通运输厅', '公路局', '港航局', '运管局', '机场局'];
    if (localStorage.division_code == '330000' && $.inArray(localStorage.career, provinceArr) != -1) $('#ghxzModal .second_trial').attr('disabled', true);
    $('.clone').remove();
    var data_index = 0;
    allData = allData == undefined ? data : allData;
    var larr = top.location.pathname.split('/'),
        type = larr[larr.length - 1].split('.')[0];
    var xmID = type == 'lnxm' ? 'XMID' : 'identifier';
    for (var i = 0; i < allData.length; i++) {
        if (allData[i][xmID] == projectId) {
            data_index = parseInt(i);
            if ($('.jmdInput').length && allData[data_index]['TABLE_JMDXX'] != undefined) {
                var valid = allData[data_index]['TABLE_JMDXX']['enable'];
                $('.jmdInput').attr('checked', valid);
                valid ? $('.jmd').addClass('color-red') : $('.jmd').removeClass('color-red');
            }
            for (var m in allData[data_index]) {
                if (allData[data_index][m] instanceof Array) {
                    $('.body').each(function (a) {
                        var dataBody = $(this).attr('data-body');
                        if (m == dataBody) {
                            var that = $(this);
                            var valArray = allData[data_index][m];
                            for (var e = 0; e < valArray.length; e++) {
                                if (e == 0) {
                                    editSigle(that, e, valArray, allData[data_index]);
                                } else {
                                    var tableName = null;
                                    switch (m) {
                                        case 'GS_NDJH_LXJSGM':
                                        case 'SY_YHGK_HDJSGM':
                                        case 'SYZCXT_JSGM':
                                            //路线建设规模信息表or航道航运建设规模信息表or水运支持系统建设规模信息表
                                            if ($('.bridgeBox').length != (e + 1)) editMuti(e, '.bridgeBox', '.bridgeWrap1');
                                            tableName = $('.bridgeBox');
                                            break;
                                        case 'GS_NDJH_QLJSGM':
                                        case 'SY_LDYS_ZYQMTJSGM':
                                            //独立桥梁建设规模信息表or陆岛运输建设规模信息表
                                            if ($('.DLbridgeBox').length != (e + 1)) editMuti(e, '.DLbridgeBox', '.bridgeWrap2');
                                            tableName = $('.DLbridgeBox');
                                            break;
                                        case 'GS_NDJH_SDJSGM':
                                        case 'SYZCXT_JSGM':
                                            //独立隧道建设规模信息表//水运支持系统建设规模信息表
                                            if ($('.DLtunnelBox').length != (e + 1)) editMuti(e, '.DLtunnelBox', '.bridgeWrap3');
                                            tableName = $('.DLtunnelBox');
                                            break;
                                        case 'GS_NDJH_KYSNJSGM':
                                        case 'SY_YHGK_FBDJSGM':
                                            //客运枢纽、物流园区建设规模信息表or水运防波堤建设规模信息表
                                            if ($('.KYSNBox').length != (e + 1)) editMuti(e, '.KYSNBox', '.bridgeWrap4');
                                            tableName = $('.KYSNBox');
                                            break;
                                    }
                                    editSigle(tableName, e, valArray, allData[data_index]);
                                }
                            }
                        }
                    })
                } else {
                    if ($('#ghxzModal').hasClass('body')) {
                        //建议计划
                        $('.body').each(function (i) {
                            var dataBody = $(this).attr('data-body');
                            var that = $(this);
                            if (m == dataBody) {
                                that.removeClass('none');
                                that.find('.data-get').each(function (a) {
                                    var dataName = $(this).attr('data-name');
                                    if (dataName == 'XZQHMC') {
                                        var value = allData[data_index][dataBody]['XZQHMC'],
                                            first = value.substring(0, 3),
                                            second = value.substring(3, 6),
                                            third = value.substring(6, value.length),
                                            code = allData[data_index][dataBody]['XZQH'];
                                        if (value.substring(0, 3) != '浙江省') {
                                            third = second;
                                            second = first;
                                            first = '浙江省';
                                        }
                                        var cityHtml = '<option value=""></option>' +
                                            '<option value="330100">杭州市</option>' +
                                            '<option value="330200">宁波市</option>' +
                                            '<option value="330300">温州市</option>' +
                                            '<option value="330400">嘉兴市</option>' +
                                            '<option value="330500">湖州市</option>' +
                                            '<option value="330600">绍兴市</option>' +
                                            '<option value="330700">金华市</option>' +
                                            '<option value="330800">衢州市</option>' +
                                            '<option value="330900">舟山市</option>' +
                                            '<option value="331000">台州市</option>' +
                                            '<option value="331100">丽水市</option>';
                                        if (second == '' && third == '') {
                                            $('.XZQHMC .xzqh-province').val(code);
                                            $('.XZQHMC .xzqh-city').empty().append(cityHtml);
                                        } else {
                                            $('.XZQHMC .xzqh-province').val('330000');
                                            $('.XZQHMC .xzqh-city').empty().append(cityHtml);
                                            if (third == '') {
                                                $('.XZQHMC .xzqh-city').val(code);
                                                for (var i in devisionc) {
                                                    if (i.substring(0, 4) == code.substring(0, 4) && i != code) {
                                                        var value = devisionc[i].substring(8, devisionc[i].length);
                                                        areaHtml += '<option value="' + i + '">' + value + '</option>';
                                                    }
                                                }
                                                areaHtml = '<option value=""></option>' + areaHtml;
                                                $('.xzqh-area').empty().append(areaHtml);
                                            } else {
                                                var secondeCode = '',
                                                    thirdCode = '',
                                                    all = first + '-' + second,
                                                    areaHtml = '';
                                                for (var a in devisionc) {
                                                    if (devisionc[a] == all) {
                                                        secondeCode = a;
                                                    }
                                                    if (devisionc[a].substring(0, 7) == all) {
                                                        devisionc[a] == all ? areaHtml += '<option value=""></option>' : areaHtml += '<option value="' + a + '">' + devisionc[a].substring(8, devisionc[a].length) + '</option>';
                                                    }
                                                }
                                                $('.XZQHMC .xzqh-city').val(secondeCode);
                                                $('.XZQHMC .xzqh-area').empty().append(areaHtml).val(code);
                                            }
                                        }
                                    } else if (dataName == 'administrative_plan' || dataName == 'XZQH') {
                                        var astr = devisionc[allData[data_index][dataBody][dataName]];
                                        $('.' + dataName).val(astr).attr('data-vercode', allData[data_index][dataBody][dataName]);
                                    } else if (dataName == 'SXM') {
                                        $('.MSXM').val(allData[data_index]['SJ_JBXX']['SXM'].substr(0, 3));
                                        $('.ZSXM').val(allData[data_index]['SJ_JBXX']['SXM'].substr(3, 1));
                                    } else {
                                        if (that.find('.' + dataName).hasClass("input") || $('.' + dataName).hasClass('textarea')) {
                                            that.find('.' + dataName).val(allData[data_index][dataBody][dataName]);
                                        } else if (that.find('.' + dataName).hasClass("select")) {
                                            if (dataName == 'JSXZ' && that.find('.JSXZ').attr('multiple') != undefined) {
                                                var array = allData[data_index][dataBody][dataName].split(',')
                                                that.find('.' + dataName).selectpicker('val', array);
                                                for (var x in array) {
                                                    switch (array[x]) {
                                                        case '':
                                                            that.find('.dropdown-menu.selectpicker li').eq(0).addClass('selected');
                                                            break;
                                                        case '新建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(1).addClass('selected');
                                                            break;
                                                        case '续建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(2).addClass('selected');
                                                            break;
                                                        case '改建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(3).addClass('selected');
                                                            break;
                                                        case '扩建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(4).addClass('selected');
                                                            break;
                                                        case '迁建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(5).addClass('selected');
                                                            break;
                                                        case '其他':
                                                            that.find('.dropdown-menu.selectpicker li').eq(6).addClass('selected');
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                            } else {
                                                that.find('.' + dataName).val(allData[data_index][dataBody][dataName]);
                                            }
                                        }
                                    }
                                    if (dataName == 'XMLXDM') {
                                        //相应表的显示隐藏
                                        switch (allData[data_index][dataBody][dataName]) {
                                            case '1':
                                                //路线
                                                $('.tableWrap').eq(0).show().siblings('.tableWrap').hide();
                                                $('.routeConstruct') ? $('.routeConstruct').show() : ""; //是否加入字段校验
                                                break;
                                            case '2':
                                                //独立大桥
                                                $('.tableWrap').eq(1).show().siblings('.tableWrap').hide();
                                                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
                                                break;
                                            case '3':
                                                //独立隧道
                                                $('.tableWrap').eq(2).show().siblings('.tableWrap').hide();
                                                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
                                                break;
                                            case '4':
                                                // 客运站场
                                                $('.tableWrap').eq(3).show().siblings('.tableWrap').hide();
                                                $('.wuliuShow').addClass('none').siblings().removeClass('none');
                                                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
                                                break;
                                            case '5':
                                                //物流园区站场
                                                $('.tableWrap').eq(3).show().siblings('.tableWrap').hide();
                                                $('.keyunShow').addClass('none').siblings().removeClass('none');
                                                $('.routeConstruct') ? $('.routeConstruct').hide() : "";
                                                break;
                                            case '99':
                                                //其他
                                                $('.tableWrap').show();
                                                break;
                                        }
                                    }
                                    if (allData[data_index][dataBody]['XMLXDM'] == '1' || allData[data_index][dataBody]['XMLXDM'] == '99') {
                                        if (dataName == 'SFBHQL') {
                                            //是否包含桥梁
                                            if (allData[data_index][dataBody][dataName] == '1') {
                                                $('.containerBri').show();
                                            } else {
                                                $('.containerBri').hide();
                                            }
                                        }
                                        if (dataName == 'SFBHSD') {
                                            if (allData[data_index][dataBody][dataName] == '1') {
                                                $('.containerTun').show();
                                            } else {
                                                $('.containerTun').hide();
                                            }
                                        }
                                    }
                                });
                            }
                        });
                    } else {
                        //五年规划
                        $('.data-type').each(function () {
                            var that = $(this);
                            that.find('.data-get').each(function (a) {
                                var dataName = $(this).attr('data-name');
                                if (m == dataName) {
                                    if (dataName == 'administrative_plan') {
                                        var astr = devisionc[allData[data_index][dataName]];
                                        $('.' + dataName).val(astr).attr('data-vercode', allData[data_index][dataName]);
                                    } else {
                                        if (that.find('.' + dataName).hasClass("input") || $('.' + dataName).hasClass('textarea')) {
                                            that.find('.' + dataName).val(allData[data_index][dataName]);
                                        } else if (that.find('.' + dataName).hasClass("select")) {
                                            if ((dataName == 'JSXZ' || dataName == 'construction_nature') && that.find('.' + dataName).attr("multiple") != undefined) {
                                                var array = allData[data_index][dataName].split(',')
                                                that.find('.' + dataName).selectpicker('val', array);
                                                that.find('.dropdown-menu.selectpicker li').removeClass('active').removeClass('selected');
                                                for (var x in array) {
                                                    switch (array[x]) {
                                                        case '':
                                                            that.find('.dropdown-menu.selectpicker li').eq(0).addClass('selected');
                                                            break;
                                                        case '新建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(1).addClass('selected');
                                                            break;
                                                        case '续建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(2).addClass('selected');
                                                            break;
                                                        case '改建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(3).addClass('selected');
                                                            break;
                                                        case '扩建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(4).addClass('selected');
                                                            break;
                                                        case '迁建':
                                                            that.find('.dropdown-menu.selectpicker li').eq(5).addClass('selected');
                                                            break;
                                                        case '其他':
                                                            that.find('.dropdown-menu.selectpicker li').eq(6).addClass('selected');
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                            } else {
                                                that.find('.' + dataName).children().map(function (index, value) {
                                                    value.innerHTML == allData[data_index][dataName] ? value.selected = true : '';
                                                })
                                            }
                                        }
                                    }
                                }
                            });
                        });
                    }
                    if (m == 'first_trial' || m == 'third_trial') {
                        var astr = '';
                        if (allData[data_index][m] != '') {
                            var reg = allData[data_index][m].match(/\d{6}/)[0];
                            astr = devisionc[reg];
                            $('.' + m).val(allData[data_index][m].replace(/\d{6}/, astr + '/'));
                            $('.' + m).attr('data-vercode', reg);
                            $('.' + m).attr('data-vername', allData[data_index][m].substr(6));
                        } else {
                            $('.' + m).val('');
                            $('.' + m).attr('data-vercode', '');
                            $('.' + m).attr('data-vername', '');
                        }
                    } else if (m == 'second_trial' && allData[data_index][m] != '') {
                        var astr = '';
                        var reg = allData[data_index][m].match(/\d{6}/)[0];
                        astr = devisionc[reg];
                        var indu = allData[data_index][m].substr(6);
                        $('.' + m + ' option').each(function (b) {
                            if ($(this).attr('data-vername') == indu) {
                                $(this).prop('selected', true);
                            }
                        });
                    }
                }
            }
        }

        $('.editHistory').on('click', function (e) {
            var dataType = $(this).attr('data-type');
            dataType == 'nc' ? ncCheck('xg') : $.contentCheck('xg');
            if (!$('#ghxzModal').find('.data-get').children().hasClass('checkErr')) {
                console.log($.newAdd(projectId));
                var datan = JSON.stringify($.newAdd(projectId));
                $.ajax({
                    type: 'post',
                    url: '/api/edit_history_project?XMID=' + projectId,
                    data: datan,
                    success: function (result) {
                        alertMs('修改成功', 1, function () {
                            location.reload();
                        })
                    },
                    error: function (error) {
                        console.log(error);
                    }
                })
            }
        });

        $('.confirmBtn').eq(1).off("click").on('click', function (e) {
            var dataType = $(this).attr('data-type');
            $('.tabContainer').hasClass('sjContainer') ? sjCheck('xg', projectId) : ($('.tabContainer').hasClass('ncContainer') ? ncCheck('xg', projectId) : $.contentCheck('xg', projectId));
            if (!$('#ghxzModal').find('.data-get').children().hasClass('checkErr') && !$('#ghxzModal').find('.zjin').hasClass('checkErr')) {
                var larr = top.location.pathname.split('.')[0].split('/'),
                    type = larr[larr.length - 1];
                var status = allData[data_index]['status'],
                    uporg = allData[data_index]['up_org'],
                    userName = allData[data_index]['user_name'],
                    datan = '',
                    acId = localStorage.acId;
                if (acId.indexOf('change_fomation') != -1) {
                    if (type == 'tl' || type == 'gs' || type == 'gsd' || type == 'sy' || type == 'zc' || type == 'jc') {
                        status = '未上报';
                        datan = JSON.stringify($.newAdd(projectId, status, uporg, userName, '1'));
                    } else {
                        status = '财务未确认';
                        datan = JSON.stringify($.newAdd(projectId, status, uporg, userName, '1'));
                    }
                } else if (acId.indexOf('fomation') != -1) {
                    if (type == 'tl' || type == 'gs' || type == 'gsd' || type == 'sy' || type == 'zc' || type == 'jc') {
                        status = '未上报';
                        datan = JSON.stringify($.newAdd(projectId, status, uporg, userName));
                    } else {
                        status = '财务未确认';
                        datan = JSON.stringify($.newAdd(projectId, status, uporg, userName));
                    }
                } else {
                    status = allData[data_index]['status'];
                    datan = JSON.stringify($.newAdd(projectId, status, uporg, userName));
                }
                if (acId == 'road_combine' && $('.selected-container tbody').length == 0 && dataType != 'editNew') {
                    alertMs('请选择关联的子项目');
                } else {
                    $(this).attr('disabled', true);
                    $.ajax({
                        type: 'post',
                        url: '/api/update_project?project_id=' + projectId,
                        data: datan,
                        success: function (result) {
                            alertMs(localStorage.acId.indexOf('change_fomation') != -1 ? '变更修改已提交完成' : '修改已提交完成', 1, function () {
                                var dataLog = [getDate(0), localStorage.name, localStorage.acId.indexOf('change_fomation') != -1 ? '变更修改了' : '修改了' + txt];
                                dataLog = JSON.stringify(dataLog);
                                $.post('/api/set_log?project_id=' + projectId, dataLog, function () {
                                    if (dataType == 'editNew') {
                                        $('#ghitemModal').show().siblings().hide();
                                        $('#ghitem').addClass('modalActive').siblings().removeClass('modalActive');
                                        $('#ghitemEdit').hide();
                                        $('html', window.top.document).animate({ scrollTop: 0 }, 1000);
                                        for (var m = 0; m < addItemArr.length; m++) {
                                            if (addItemArr[m]['identifier'] == result['identifier']) {
                                                addItemArr[m] = result;
                                            }
                                        }
                                        $.addItem('.selected-container', type);
                                    } else if (acId.indexOf('fomation') != -1 || acId == 'road_combine') {
                                        location.reload();
                                    }
                                })
                            })
                        },
                        error: function (error) {
                            console.log(error);
                        }
                    });
                }
            }
        })
    }

    // 子项目 
    var itemList = allData[data_index]['item_list'],
        tdHtml = '',
        trHtml = '';

    if (itemList != undefined) (selectItemArr = addItemArr.concat(itemList)) && $.createItem('.selected-container', itemList, type);

    //附件
    if (!!allData[data_index].GS_NDJH_FJXX) {
        var file = allData[data_index].GS_NDJH_FJXX;
        var fileTb = '';
        for (var a = 0; a < file.length; a++) {
            var fjlx = file[a].FJLX;
            var fjlxSelect = '<select><option value="">-请选择-</option><option>公可相关</option><option>初设相关</option><option>其他</option></select>';
            if (fjlx != '') {
                var reg = '>' + fjlx + '';
                fjlxSelect = fjlxSelect.replace(reg, ' selected' + reg);
            }
            fileTb += '<tr data-id="' + file[a].FJURL.split('?')[1] + '" data-url="' + file[a].FJURL.split('?')[0] + '"><td>' + file[a].FJMC + '</td><td>' + file[a].file_size + '</td><td class="fileType">' + fjlxSelect + '</td><td><input type="text" class="fileInp" value="' + file[a].FJMS + '"></td><td>' + file[a].up_user + '</td><td>' + file[a].SCTIME + '</td></tr>';
        }
        $('.fjContainer tbody').empty().append(fileTb);
    }
    //资金来源
    if (!!allData[data_index].GS_NDJH_TZXX) {
        var source = allData[data_index].GS_NDJH_TZXX;
        var sourceTb = '';
        for (var b = 0; b < source.length; b++) {
            //资金来源代码
            var jhzjly = source[b].JHZJLY;
            var jhzjlySelect = '<select style="width:100%; height:100%; border:0px;" class="zjin"><option value="">--请选择--</option><option value="01">车购税</option><option value="02">中央国债</option><option value="03">地方自筹</option><option value="04">国内贷款</option><option value="05">利用外资</option><option value="06">港建费</option><option value="07">预算内</option><option value="09">其他</option></select>';
            if (jhzjly != '') {
                var regly = '' + jhzjly + '"';
                jhzjlySelect = jhzjlySelect.replace(regly, regly + ' selected');
            }
            //是否能落实
            var sfnls = source[b].SFNLS;
            var sfnlsSelect = '<select style="width:100%; height:100%; border:0px;" class="zjin"><option value="">--请选择--</option><option value="1">是</option><option value="2">否</option></select>';
            if (sfnls != '') {
                var regls = '' + sfnls + '"';
                sfnlsSelect = sfnlsSelect.replace(regls, regls + ' selected');
            }
            //投资类别
            var tzlb = source[b].TZLB;
            var tzlbSelect = '<select style="width:100%; height:100%; border:0px;" class="zjin"><option value="">--请选择--</option><option value="98">本批</option><option value="99">本年</option></select>'
            if (tzlb != '') {
                var reglb = '' + tzlb + '"';
                tzlbSelect = tzlbSelect.replace(reglb, reglb + ' selected');
            }
            sourceTb += '<tr><td>' + jhzjlySelect + '</td><td><input type="text" style="width:100%; height:100%; border:0px;" value="' + source[b].JHZJSE + '"></td><td>' + sfnlsSelect + '</td><td>' + tzlbSelect + '</td></tr>';
        }
        $('.source tbody').empty().append(sourceTb);
    }

    //批复文号
    if (!!allData[data_index].reply_xx) {
        var reply = allData[data_index].reply_xx;
        var replyTb = '';
        for (var c = 0; c < reply.length; c++) {
            var pflx = '<select style="width:100%; height:100%; border:1px solid #fff"><option value="">--请选择--</option><option value="工可批复文号">工可批复文号</option><option value="初设批复文号">初设批复文号</option><option value="承诺函文号">承诺函文号</option><option value="其他">其他</option></select>';
            var reglx = '' + reply[c]['pflx'] + '"';
            pflx = pflx.replace(reglx, reglx + ' selected');
            replyTb += '<tr><td>' + pflx + '</td><td><input type="text" style="width:100%; height:100%; border:1px solid #fff" value="' + reply[c].pfwh + '"></td><td><input class="datetimepicker" type="text" style="width:100%; height:100%; border:1px solid #fff" value="' + reply[c].pfsj + '"></td><td><input class="datetimepicker endDate" type="text" style="width:100%; height:100%; border:1px solid #fff" value="' + reply[c].pfjssj + '"></td></tr>';
        }
        $('.replyTab tbody').empty().append(replyTb);
    }
    // 控制点
    if (!!allData[data_index].T_LXKZD && allData[data_index]['T_LXKZD'].length) {
        if (allData[data_index]['T_LXKZD'][0].length) {
            var kzdArr = allData[data_index].T_LXKZD;
            for (var q = 0; q < kzdArr.length; q++) {
                var kzdHtml = '';
                for (var w = 0; w < kzdArr[q].length; w++) {
                    var wz = kzdArr[q][w]['WZBS'];
                    kzdHtml += '<tr><td>' + (wz == '1' ? '起点' : (wz == '2' ? '讫点' : '中间点')) + '</td>' +
                        '<td>' + kzdArr[q][w]['SXH'] + '</td>' +
                        '<td>' + kzdArr[q][w]['SZDMC'] + '</td>' +
                        '<td>' + kzdArr[q][w]['JD'] + '</td>' +
                        '<td>' + kzdArr[q][w]['WD'] + '</td>' +
                        '<td><span class="kzd_del">删除</span><span class="kzd_edit" data-index="' + parseInt(w + 1) + '">修改</span></td>' +
                        '</tr>';
                }
                $('.kzd-table').eq(q).find('table>tbody').empty().append(kzdHtml);
            }
            mapPolyline();
        }
    }
    //地图赋值
    if (!!allData[data_index].map_local) {
        var maparray = allData[data_index].map_local;
        mapPolyline(maparray);
        sessionStorage.setItem('mapArray', maparray.join('/'));
    }
}

//统计分析表格
function createTable(result, type) {
    $('.table-container tbody>tr .category').each(function (x) {
        var index = $(this).attr('data-index');
        for (var i = 0; i < result[x].length; i++) {
            var value = result[x][i] == 0 ? '' : result[x][i];
            $(this).parent().find('td').eq(index - 0 + i).html(value);
        }
    });
}

// 五年规划综合查询
function fiveTotal(result, type) {
    if (type == 0) {
        $('.table-container tbody>tr').each(function (x) {
            for (var a = 0; a < result[x].length; a++) {
                var value = result[x][a] == 0 ? '' : result[x][a];
                $(this).find('td').eq(a + 3).html(value);
            }
        });
    } else {
        $('.table-container tbody tr .category').each(function (x) {
            var index = $(this).attr('data-index');  //3
            for (var a = 0; a < result[x].length; a++) {
                switch (x) {
                    case 2: case 3: case 4: case 6:
                        if (a == 0) {
                            $(this).parent().find('td').eq(3).html('建设规模' + result[x][0] + '公里');
                        } else {
                            $(this).parent().find('td').eq(index - 0 + a).html(result[x][a]);
                        }
                        break;
                    case 7: case 8: case 9: case 10: case 11: case 12:
                        if (a == 2) {
                            $(this).parent().find('td').eq(3).html('建设规模' + result[x][0] + '公里<br>(其中一级公路' + result[x][1] + '公里、二级公路' + result[x][2] + '公里)');
                        } else if (a > 2) {
                            $(this).parent().find('td').eq(index - 0 + a - 2).html(result[x][a]);
                        }
                        break;
                    case 14: case 15: case 16:
                        if (a == 1) {
                            $(this).parent().find('td').eq(3).html('占地面积' + result[x][1] + '亩建筑面积' + result[x][1] + '平方米');
                        } else if (a > 1) {
                            $(this).parent().find('td').eq(index - 0 + a - 1).html(result[x][a]);
                        }
                        break;
                    case 18:
                        if (a == 4) {
                            $(this).parent().find('td').eq(3).html('建成泊位' + result[x][0] + '个，深水泊位' + result[x][1] + '个，建设航道长度' + result[x][2] + '公里；<br>新增通过能力' + result[x][3] + '万吨，新增航道' + result[x][4] + '公里');
                        } else if (a > 4) {
                            $(this).parent().find('td').eq(index - 0 + a - 4).html(result[x][a]);
                        }
                        break;
                    case 19:
                        if (a == 2) {
                            $(this).parent().find('td').eq(3).html('建成泊位' + result[x][0] + '个，深水泊位' + result[x][1] + '个，新增通过能力' + result[x][2] + '万吨');
                        } else if (a > 2) {
                            $(this).parent().find('td').eq(index - 0 + a - 2).html(result[x][a]);
                        }
                        break;
                    case 20:
                        if (a == 1) {
                            $(this).parent().find('td').eq(3).html('建设航道长度' + result[x][0] + '公里，新增航道' + result[x][1] + '公里');
                        } else if (a > 1) {
                            $(this).parent().find('td').eq(index - 0 + a - 1).html(result[x][a]);
                        }
                        break;
                    case 21:
                        if (a == 3) {
                            $(this).parent().find('td').eq(3).html('建设泊位' + result[x][0] + '个，建设内河航道' + result[x][1] + '公里；<br>新增吞吐能力' + result[x][2] + '万吨，新增航道' + result[x][3] + '公里');
                        } else if (a > 3) {
                            $(this).parent().find('td').eq(index - 0 + a - 3).html(result[x][a]);
                        }
                        break;
                    case 22:
                        if (a == 1) {
                            $(this).parent().find('td').eq(3).html('建成泊位' + result[x][0] + '个，新增吞吐能力' + result[x][1] + '万吨');
                        } else if (a > 1) {
                            $(this).parent().find('td').eq(index - 0 + a - 1).html(result[x][a]);
                        }
                        break;
                    case 23:
                        if (a == 1) {
                            $(this).parent().find('td').eq(3).html('建设内河航道' + result[x][0] + '公里，新增航道' + result[x][1] + '公里');
                        } else if (a > 1) {
                            $(this).parent().find('td').eq(index - 0 + a - 1).html(result[x][a]);
                        }
                        break;
                    case 24:
                        if (a == 1) {
                            $(this).parent().find('td').eq(3).html('建成泊位' + result[x][0] + '个');
                        } else if (a > 1) {
                            $(this).parent().find('td').eq(index - 0 + a - 1).html(result[x][a]);
                        }
                        break;
                    case 26:
                        if (a == 2) {
                            $(this).parent().find('td').eq(3).html('运输机场达到' + result[x][0] + '个。其中航站楼面积达到' + result[x][1] + '万平方米；吞吐能力达到' + result[x][2] + '万人次');
                        } else if (a > 2) {
                            $(this).parent().find('td').eq(index - 0 + a - 2).html(result[x][a]);
                        }
                        break;
                    case 27:
                        if (a == 0) {
                            $(this).parent().find('td').eq(3).html('新建、改扩建一、二类通用机场' + result[x][0] + '个以上');
                        } else {
                            $(this).parent().find('td').eq(index - 0 + a).html(result[x][a]);
                        }
                        break;
                    default:
                        $(this).parent().find('td').eq(index - 0 + a).html(result[x][a]);
                        break;
                }
            }
        })
    }
}

// 建议计划综合查询
function jhConverse(result) {
    var totalNum = result['total_num'],
        totalPage = Math.ceil(totalNum / everyNum);
    total = result['total'],
        list = result['list'];
    $('.inputsTyle').eq(4).val(totalNum);
    $('.pageTotally').val(totalPage);
    var allHtml = '';
    for (var i = 0; i < total.length; i++) {
        var value = total[i] == 0 ? '' : total[i];
        allHtml += '<td>' + value + '</td>';
    }
    allHtml = '<tr><td>合计</td>' + allHtml + '</tr>';
    var tdHtml = '',
        trHtml = '';
    for (var a = 0; a < list.length; a++) {
        tdHtml = '<td>' + parseInt(a + 1) + '</td>';
        for (var b = 0; b < list[a].length; b++) {
            var value = list[a][b] == 0 ? '' : list[a][b];
            tdHtml += '<td>' + value + '</td>';
        }
        trHtml += '<tr>' + tdHtml + '</tr>';
    }
    allHtml = allHtml + trHtml;
    $('.table-container tbody').empty().append(allHtml);
}

// 省投资综合查询
function sjConverse(result, projectType, showType) {
    // projectType: sjlw  showType: 0
    $('.table-container tbody>tr .category').each(function (x) {
        var index = $(this).attr('data-index');
        for (var a = 0; a < result[x].length; a++) {
            var value = result[x][a] == 0 ? '' : result[x][a];
            $(this).parent().find('td').eq(index - 0 + a).html(value);
        }
    });
}

// 农村公路建议统计分析
function ncConverse(result, showType) {
    $('.table-container tbody>tr .category').each(function (x) {
        var index = $(this).attr('data-index');
        for (var a = 0; a < result[x].length; a++) {
            var value = result[x][a] == 0 ? '' : result[x][a];
            $(this).parent().find('td').eq(index - 0 + a).html(value);
        }
    });
}


//地图折线点
function mapPolyline(maparray) {
    //maparray：正常地图 
    var lonAndlat = [],
        pointArray = [],
        doneArray = {};
    var ellipse = null;
    pline = null;
    // sessionStorage.removeItem('mapArray');
    if (!bookmarkFun) {
        bookmarkFun = MEvent.addListener(maplet, "bookmark", bookmark_done);
        maplet.setMode("bookmark");
    } else {
        MEvent.removeListener(bookmarkFun);
        bookmarkFun = null;
        bookmarkFun = MEvent.addListener(maplet, "bookmark", bookmark_done);
        maplet.setMode("bookmark");
    }

    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    if (type != 'gljy') {
        var pointArray = [];
        //点是否已填
        var start_lon = start_lat = end_lon = end_lat = '';
        $('.mapdegree input').each(function (i) {
            $(this).on('change', function () {
                var inpClass = $(this).parent().attr('data-name');
                switch (inpClass) {
                    case 'QDJINGDU':
                        start_lon = $('.' + inpClass).val();
                        doneArray.start_lon = start_lon;
                        existPline(doneArray);
                        break;
                    case 'QDWEIDU':
                        start_lat = $('.' + inpClass).val();
                        doneArray.start_lat = start_lat;
                        existPline(doneArray);
                        break;
                    case 'ZDJINGDU':
                        end_lon = $('.' + inpClass).val();
                        doneArray.end_lon = end_lon;
                        existPline(doneArray);
                        break;
                    case 'ZDWEIDU':
                        end_lat = $('.' + inpClass).val();
                        doneArray.end_lat = end_lat;
                        existPline(doneArray);
                        break;
                }
            });
        });
    }

    if (!!maparray) {
        for (var a = 0; a < maparray.length; a++) {
            for (var b = 0; b < maparray[a].length; b++) {
                var lon = maparray[a][b].split(',')[0],
                    lat = maparray[a][b].split(',')[1];
                if (b == 0) {
                    var center = new MPoint(lon, lat);
                    pline = new MPolyline([center], new MBrush());
                    maplet.addOverlay(pline);
                    addMEllipse(center);
                } else {
                    pline.appendPoint(new MPoint(lon, lat), true);
                    if (ellipse != null) {
                        maplet.hideBubble();
                        maplet.removeOverlay(ellipse);
                    }
                    pline.setEditable(true);
                    MEvent.addListener(maplet, "edit", editEnd);
                }
            }
        }
    }

    //当点已填时生成
    function existPline(obj) {
        var start_lon = obj['start_lon'],
            start_lat = obj['start_lat'],
            end_lon = obj['end_lon'],
            end_lat = obj['end_lat'];
        lonLat = [];
        if (!!start_lon && !!start_lat && !!end_lon && !!end_lat) {
            pointArray = [];
            if (pline) {
                maplet.removeOverlay(pline);
                pline = null;
            }
            pline = new MPolyline(
                [
                    new MPoint(start_lon, start_lat),
                    new MPoint(end_lon, end_lat)
                ], new MBrush()
            );
            maplet.addOverlay(pline);
            pline.setEditable(true);
            MEvent.addListener(maplet, "edit", editEnd);
            var start = [];
            start.push(start_lon);
            start.push(start_lat);
            pointArray.push(start);
            var end = [];
            end.push(end_lon);
            end.push(end_lat);
            pointArray.push(end);
            point = pointArray.join('/');
            sessionStorage.setItem('mapArray', point);
        }
    }

    //单击获取经纬度
    function bookmark_done(data) {
        lonAndlat = [];
        var lon = data.point.lon; //经度
        lonAndlat.push(lon);
        var lat = data.point.lat; //纬度
        lonAndlat.push(lat);
        pointArray.push(lonAndlat);
        maplet.setMode("bookmark");
        polyLine(lonAndlat);
    }

    var kzdArr = [],
        kzdAll = [],
        xmlb = $('.XMLB option:selected').val(),
        kzdPline = null;
    kzdPlineArr = [];
    $('.kzd-table tbody>tr').each(function (i) {
        var wz = $(this).find('td').eq(0).html();
        kzdArr.push(new MPoint($(this).find('td').eq(3).html(), $(this).find('td').eq(4).html()));
        if (wz == '讫点') {
            kzdAll.push(kzdArr);
            kzdArr = [];
        }
        if (i == 0) {
            if (wz != '起点') {
                alertMs('第一个点必须是起点');
                return false;
            }
        } else {
            var beforeWz = $(this).prev().find('td').eq(0).html();
            if (beforeWz == '起点' || beforeWz == '中间点') {
                if (wz == '起点') {
                    $(this).find('td').eq(0).addClass('kzdCheckErr');
                    alertMs(beforeWz + '后的一个点不能为' + wz);
                    return false;
                } else {
                    return dis(kzdArr, $(this));
                }
            } else if (beforeWz == '讫点') {
                if (wz == '中间点' || wz == '讫点') {
                    $(this).find('td').eq(0).addClass('kzdCheckErr');
                    alertMs(beforeWz + '后的一个点不能为' + wz);
                    return false;
                }
            }
        }
        if (i == $('.kzd-table tbody>tr').length - 1) {
            if (wz != '讫点') {
                $(this).find('td').eq(0).addClass('kzdCheckErr');
                alertMs('最后一个点必须为讫点');
                return false;
            }
        }
    });

    // 判断控制点距离
    function dis(kzdArr, that) {
        var length = kzdArr.length;
        var dis = maplet.measDistance([kzdArr[length - 2], kzdArr[length - 1]]);
        // var dis = maplet.measDistance([new MPoint(kzdArr[length - 2][0], kzdArr[length - 2][1]), new MPoint(kzdArr[length - 1][0], kzdArr[length - 1][1])]);
        if (xmlb == '0102' && parseInt(dis) > 10000) {
            that.find('td').eq(3).addClass('kzdCheckErr') && that.find('td').eq(4).addClass('kzdCheckErr');
            alertMs('两个控制点之间的距离最大不超过10公里');
            return false;
        } else if (xmlb != '0102' && parseInt(dis) > 500) {
            that.find('td').eq(3).addClass('kzdCheckErr') && that.find('td').eq(4).addClass('kzdCheckErr');
            alertMs('两个控制点之间的距离不超过500米');
            return false;
        } else {
            return true;
        }
    }

    if (!$('.kzd-table table tbody>tr').find('td').hasClass('kzdCheckErr') && kzdAll.length > 0) {
        for (var j = 0; j < kzdAll.length; j++) {
            kzdPline = new MPolyline(kzdAll[j], new MBrush());
            kzdPlineArr.push(kzdPline);
            maplet.addOverlay(kzdPline);
        }
    }

    //折线
    function polyLine(pointarray) {
        if (!pline) {
            var center = new MPoint(pointarray[0], pointarray[1]);
            pline = new MPolyline([center], new MBrush());
            maplet.addOverlay(pline);
            addMEllipse(center);
        } else {
            pline.appendPoint(new MPoint(pointarray[0], pointarray[1]), true);
            if (ellipse != null) {
                maplet.hideBubble();
                maplet.removeOverlay(ellipse);
            }
            pline.setEditable(true);
            MEvent.addListener(maplet, "edit", editEnd);
        }
        //右键撤销
        $('.mapcontextmenu').click(function () {
            MEvent.removeListener(bookmarkFun);
        });
        //生成
        $('#myMap').click(function () {
            if (!bookmarkFun) {
                bookmarkFun = MEvent.addListener(maplet, "bookmark", bookmark_done);
                maplet.setMode("bookmark");
            }
        });
        if (!!maparray) {
            point = maparray.join('/') + '/';
            point += pointArray.join('/');
            sessionStorage.setItem('mapArray', point);
        } else {
            point = pointArray.join('/');
            sessionStorage.setItem('mapArray', point);
        }


    }

    //获取拖拽后的点
    function editEnd(overlay) {
        // var msg = "";
        pointArray = [];
        for (var i = 0; i < overlay.pts.length; i++) {
            lonAndlat = [];
            var lon = overlay.pts[i].lon; //经度
            lonAndlat.push(lon);
            var lat = overlay.pts[i].lat; //纬度
            lonAndlat.push(lat);
            pointArray.push(lonAndlat);
        }
        point = pointArray.join('/');
        sessionStorage.setItem('mapArray', point);
    }

    //添加圆
    function addMEllipse(ctr) {
        var sax = say = 300;
        var brush = new MBrush();
        brush.color = "green";
        brush.bgcolor = "gray";
        brush.fill = true;
        brush.transparency = 80;
        brush.bgtransparency = 30;
        ellipse = new MEllipse(ctr, sax, say, brush);
        maplet.addOverlay(ellipse);
    }
}


//警告功能 - start
/**
 * this is a method replacing the alert and confirm
 * @param  {object or string} options       the content of alert things
 * @param  {number} opt_warntype  chooce alert type or confirm type or original
 * @param  {function} opt_callback1 return function of confirm
 * @param  {function} opt_callback2 return function of cancle
 * @return {html}               change the alert style
 */
function alertMs(options, opt_warntype, opt_callback1, opt_callback2) {
    var option = {
        warnType: 1, //1 为alert型; 2 为confirm型; 3 为系统alert型
        Title: "消息",
        Message: "错误",
        theme: "#850b06" //"red","blue","green","yellow"可以在generateCSS的themes添加对象
    };
    var generate = {
        HTML: function (option) {
            var $html = "" +
                "<div id=\"msOut\">" +
                "    <div id=\"msBox\">" +
                "        <div class=\"msTitle\">" + option.Title + "</div>" +
                "        <div class=\"msMessage\">" + option.Message + "</div>" +
                "        <div class=\"msBtn\">" +
                "            <span class=\"msConfirm\">确定</span>" +
                (option.warnType == 2 ? "<span class=\"msReject\">取消</span>" : "") +
                "        </div>" +
                "    </div>" +
                "    <div class=\"msLayer\"></div>" +
                "</div>";
            $('body').append($html);
            this.CSS(option);
        },
        CSS: function (option) {
            var themes = {
                "red": "#CC3300",
                "blue": "#99CCFF",
                "green": "#00FF99",
                "yellow": "#FFFF66"
            };
            var themeColor = themes[option.theme];
            for (var color in themes) {
                if (color == option.theme) {
                    themeColor = themes[color];
                    break;
                } else themeColor = option.theme;
            }
            $("#msOut").css({
                "width": '100%',
                "height": '100%',
                "zIndex": '99999',
                "position": 'fixed',
                "top": '0',
                "left": '0'
            });
            $(".msLayer").css({
                "width": '100%',
                "height": '100%',
                "filter": 'Alpha(opacity=40)',
                "backgroundColor": '#000',
                "opacity": '0.4'
            });
            $("#msBox").css({
                "width": '500px',
                "height": '300px',
                "zIndex": '99999',
                "position": 'absolute',
                "opacity": "0"
            });
            $(".msTitle").css({
                "display": 'block',
                "fontSize": '14px',
                "color": '#444',
                "padding": '10px 15px',
                "backgroundColor": '#f0f4f7',
                "borderRadius": '15px 15px 0 0',
                "borderBottom": '3px solid ' + themeColor,
                "fontWeight": 'bold'
            });
            $(".msMessage").css({
                "padding": " 50px",
                "line-height": " 22px",
                "background-color": "#393D49",
                "color": "#fff",
                "font-weight": "300",
                "overflow": "hidden",
                "text-overflow": "ellipsis"
            });
            $(".msBtn").css({
                "padding": '15px 0 10px 0',
                "borderRadius": '0 0 15px 15px',
                "textAlign": 'center',
                "background-color": "#f0f4f7"
            });
            $(".msConfirm").css({
                "display": "inline-block",
                "height": "28px",
                "line-height": "28px",
                "margin": "0 6px",
                "padding": "0 15px",
                "border": "1px solid" + themeColor,
                "background-color": themeColor,
                "color": " #fff",
                "border-radius": "2px",
                "font-weight": "400",
                "cursor": "pointer",
                "text-decoration": "none"
            });
            $(".msReject").css({
                "display": "inline-block",
                "height": "28px",
                "line-height": "28px",
                "margin": "0 6px",
                "padding": "0 15px",
                "border": "1px solid #dedede",
                "background-color": "#f1f1f1",
                "color": "#333",
                "border-radius": "2px",
                "font-weight": "400",
                "cursor": "pointer",
                "text-decoration": "none"
            });
            this.Event(opt_callback1, opt_callback2);
        },
        Event: function (opt_callback1, opt_callback2) {
            var pathname = window.location.pathname.split('/')[2];
            var $width = '',
                $height = '';
            if (!!pathname) {
                $width = window.parent.document.documentElement.clientWidth - $('.aside', parent.document).width(); //屏幕宽
                $height = window.parent.document.documentElement.clientHeight; //屏幕高
            } else {
                $width = document.documentElement.clientWidth; //屏幕宽
                $height = document.documentElement.clientHeight; //屏幕高
            }
            var boxWidth = $("#msBox").width();
            var boxHeight = $("#msBox").height();
            $("#msBox").css({
                "left": ($width - boxWidth) / 2 + "px"
            });
            $("#msBox").stop().animate({
                "top": ($height - boxHeight) / 2 + "px",
                "left": ($width - boxWidth) / 2 + "px",
                "opacity": "1"
            }, 300);
            $(".msConfirm").click(function () {
                $("#msBox").stop().animate({
                    "top": "0",
                    "opacity": "0.2"
                }, 300, function () {
                    $("#msOut").remove();
                });
                if (typeof opt_callback1 === "function") {
                    opt_callback1();
                    $('.msOut').remove()
                }
            });
            $(".msReject").click(function () {
                $("#msBox").stop().animate({
                    "top": "0",
                    "opacity": "0.2"
                }, 300, function () {
                    $("#msOut").remove();
                });
                if (typeof opt_callback2 === "function") {
                    opt_callback2();
                    $('.msOut').remove()
                }
            });
        }
    }
    if (typeof options === "string") {
        option.Message = options;
        if (typeof opt_warntype === "number") {
            if (opt_warntype != 3) {
                option = $.extend(option, {
                    warnType: opt_warntype
                });
                generate.HTML(option);
            } else {
                alert(option.Message);
            }
        } else if (typeof opt_warntype === "function") {
            opt_callback1 = opt_warntype;
            generate.HTML(option);
        } else {
            generate.HTML(option);
        }
    } else if (typeof options === "object") {
        option = $.extend(option, options);
        if (typeof opt_warntype === "number") {
            if (opt_warntype != 3) {
                option = $.extend(option, {
                    warnType: opt_warntype
                });
                generate.HTML(option);
            } else {
                alert(option.Message);
            }
        } else if (typeof opt_warntype === "function") {
            option = $.extend(option, options);
            opt_callback1 = opt_warntype;
            generate.HTML(option);
        } else {
            generate.HTML(option);
        }
    }
}
//end - 警告功能

//删除行
function delData(i, delType) {
    var trActive = '',
        index = -1,
        txt = '';
    if (!!i) {
        trActive = $('.data-table tbody tr:nth-child(' + i + ')');
        if (trActive.hasClass('forbidden')) {
            alertMs('你没有操作' + trActive.children().eq(2).html() + '的权限');
            return false;
        }
        index = i;
        txt = trActive.children().eq(1).html();
        alertMs('确定删除' + txt, 2, function () {
            //删除data中对应的数据并更新table
            var larr = top.location.pathname.split('.')[0].split('/'),
                type = larr[larr.length - 1];
            var parentActive = $('[id^=lnxm_sj].active,[id^=lnxm_jt].active', parent.document);
            var url = type == 'lnxm' ? (parentActive.length == 0 ? ('/api/del_history_project?XMID=' + trActive.attr('data-id')) : ('/api/del_project?project_id=' + trActive.attr('data-id'))) : ('/api/del_project?project_id=' + trActive.attr('data-id'));
            $.post(url, {}, function () {
                trActive.remove();
                location.reload();
            })
            // $.pageQuery(nowPage, everyNum);
        })
    } else {
        var Active = $('.data-table tbody tr>td:first-child input[type="checkbox"]:checked');
        trActive = Active.parents('tr');
        if (trActive.hasClass('forbidden')) {
            alertMs('你没有操作' + trActive.children().eq(2).html() + '的权限');
            return false;
        } else {
            switch (Active.length) {
                case 0:
                    alertMs('请选择删除的项目');
                    break;
                case 1:
                    trActive = Active.parents('tr');
                    txt = trActive.children().eq(2).html();
                    alertMs('确定删除' + txt, 2, function () {
                        //删除data中对应的数据并更新table
                        var larr = top.location.pathname.split('.')[0].split('/'),
                            type = larr[larr.length - 1];
                        var parentActive = $('[id^=lnxm_sj].active,[id^=lnxm_jt].active', parent.document);
                        var url = type == 'lnxm' ? (parentActive.length == 0 ? ('/api/del_history_project?XMID=' + trActive.attr('data-id')) : ('/api/del_project?project_id=' + trActive.attr('data-id'))) : ('/api/del_project?project_id=' + trActive.attr('data-id'));
                        $.post(url, {}, function () {
                            trActive.remove();
                            location.reload();
                        })
                        // $.pageQuery(10);
                    })
                    break;
                default:
                    alertMs('只能勾选一条数据进行删除');
                    break;
            }
        }
    }
}

//确认报表改变状态
function bbStatus(buttonType, index) {
    var status = '',
        txt = '',
        trActive = $('.data-table tbody tr:nth-child(' + index + ')'),
        projectId = trActive.attr('data-id');
    if (buttonType == '确认') {
        status = '已确认';
        txt = trActive.children().eq(1).html();
    }
    var trActive = $('.data-table tbody tr:nth-child(' + index + ')'),
        projectId = trActive.attr('data-id');
    if (trActive.hasClass('forbidden')) {
        alertMs('你没有操作' + txt + '的权限');
        return false;
    } else if (trActive.find('.status').html() != '未确认' && trActive.find('.status') != undefined) {
        alertMs('只能确认未确认的报表');
        return false;
    } else {
        alertMs(buttonType + '报表：' + txt + '', 2, function () {
            $.post('/api/enrol_project?project_id=' + projectId + '&status=' + encodeURI(status) + '&user_name=' + localStorage.user_name, {}, function () {
                location.reload();
            })
        })
    }
}

//上报提醒or财务确认提醒
function upload(buttonType, step) {
    var forbiddenName = [],
        projectName = [],
        projectId = '',
        project_id = [],
        confirm = [],
        thClass = getThead()[0];
    var firstIndex = $.inArray('初审机构', thClass),
        secondIndex = $.inArray('审查机构', thClass);
    var oneProject = '',
        twoProject = '',
        threeProject = '';
    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    var uploadBool = true;
    $('#myTable tbody tr>td:first-child input[type="checkbox"]').each(function (i) {
        if ($(this).is(':checked')) {
            var innerHtml = $(this).parents('tr').children().eq(1)[0].innerHTML;
            if (buttonType == '财务确认') {
                if (step == 'one') {
                    if ($(this).parents('tr').hasClass('forbidden')) {
                        forbiddenName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                    } else if (innerHtml.indexOf('财务未确认') != -1) {
                        projectName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                        projectId += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';'
                        project_id.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id'));
                    } else {
                        confirm.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                    }
                } else {
                    if ($(this).parents('tr').hasClass('forbidden')) {
                        forbiddenName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                    } else if (innerHtml.indexOf('审核接收财务未确认') != -1) {
                        projectName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                        projectId += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';'
                        project_id.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id'));
                    } else {
                        confirm.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                    }
                }
            } else if (buttonType == '确认') {
                projectId += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';';
                projectName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
            } else {
                //上报
                if (!$(this).parents('tr').hasClass('forbidden')) {
                    var activeHtml = $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(1)[0].innerHTML;
                    if (type == 'gljy' || type == 'syjy' || type == 'zcxt') {
                        if (activeHtml.indexOf('未上报') == -1) {
                            if (activeHtml.indexOf('财务未确认') != -1) {
                                alertMs('未进行财务确认');
                                return false;
                            } else {
                                forbiddenName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                            }
                        }
                    }
                    if (activeHtml.indexOf('未接收') != -1) {
                        alertMs('只能上报财务未确认或未上报的项目');
                        uploadBool = false;
                        return false;
                    } else {
                        projectName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML);
                        project_id.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id'));
                        if ($(this).parents('tr').find('td').eq(firstIndex).html() == '' && $(this).parents('tr').find('td').eq(secondIndex).html() == '') {
                            threeProject += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';';
                        } else if ($(this).parents('tr').find('td').eq(firstIndex).html() == '') {
                            twoProject += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';';
                        } else {
                            oneProject += $('#myTable tbody>tr:nth-child(' + (i + 1) + ')').attr('data-id') + ';';
                        }
                    }
                } else {
                    forbiddenName.push($('#myTable tbody>tr:nth-child(' + (i + 1) + ')').children().eq(2)[0].innerHTML)
                };
            }
        }
    });
    if (!$('#myTable tbody tr>td:first-child input[type="checkbox"]').is(':checked')) alertMs('请选择' + buttonType + '项目');
    if (forbiddenName.length != 0) {
        alertMs('你没有操作' + forbiddenName.join('，') + '的权限');
        return false;
    }
    if (confirm.length != 0) {
        step == 'one' ? alertMs('只能对财务未确认的项目进行确认') : alertMs('只能对审核接收财务未确认的项目进行确认');
        return false;
    }
    var Txt = '',
        status = '';
    if (projectName.length != 0 && uploadBool) {
        Txt = projectName.join('，');
        status = step == 'one' ? '未上报' : '审核中';
        alertMs(buttonType + '项目：' + Txt + '', 2, function () {
            if (oneProject != '') {
                status = '初审未接收';
                $.post('/api/enrol_project?project_id=' + oneProject.substring(0, oneProject.length - 1) + '&status=' + encodeURI(status) + '&user_name=' + localStorage.user_name, {}, function () {
                    $.each(oneProject.split(';'), function (key, value) {
                        var dataLog = [getDate(0), localStorage.name, buttonType + '了' + projectName[key]];
                        dataLog = JSON.stringify(dataLog);
                        $.post('/api/set_log?project_id=' + value, dataLog, function () {
                            location.reload();
                        })
                    })
                })
            }
            if (twoProject != '') {
                status = '审查未接收';
                $.post('/api/enrol_project?project_id=' + twoProject.substring(0, twoProject.length - 1) + '&status=' + encodeURI(status) + '&user_name=' + localStorage.user_name, {}, function () {
                    $.each(twoProject.split(';'), function (key, value) {
                        var dataLog = [getDate(0), localStorage.name, buttonType + '了' + projectName[key]];
                        dataLog = JSON.stringify(dataLog);
                        $.post('/api/set_log?project_id=' + value, dataLog, function () {
                            location.reload();
                        })
                    })
                })
            }
            if (threeProject != '') {
                status = '审核未接收';
                $.post('/api/enrol_project?project_id=' + threeProject.substring(0, threeProject.length - 1) + '&status=' + encodeURI(status) + '&user_name=' + localStorage.user_name, {}, function () {
                    $.each(threeProject.split(';'), function (key, value) {
                        var dataLog = [getDate(0), localStorage.name, buttonType + '了' + projectName[key]];
                        dataLog = JSON.stringify(dataLog);
                        $.post('/api/set_log?project_id=' + value, dataLog, function () {
                            location.reload();
                        })
                    })
                })
            }
            if (oneProject == '' && twoProject == '' && threeProject == '') {
                if (localStorage.acId == 'road_combine') {
                    status = /^(sj)/.test(type) ? '已下达' : '审核通过审批未接收';
                }
                $.post('/api/enrol_project?project_id=' + projectId.substring(0, projectId.length - 1) + '&status=' + encodeURI(status) + '&user_name=' + localStorage.user_name, {}, function () {
                    location.reload();
                    $.each(projectId.split(';'), function (key, value) {
                        var dataLog = [getDate(0), localStorage.name, buttonType + '了' + projectName[key]];
                        dataLog = JSON.stringify(dataLog);
                        $.post('/api/set_log?project_id=' + value, dataLog, function () {
                            location.reload();
                        })
                    })
                })
            }
        })
    }
}

//取消上报
function cancelUpload() {
    var trActive = '',
        index = '',
        txt = '';
    var Active = $('#myTable tbody tr>td:first-child input[type="checkbox"]:checked');
    switch (Active.length) {
        case 0:
            alertMs('请选择要取消上报的项目');
            return false;
            break;
        case 1:
            $('#myTable tbody tr').each(function (i) {
                if ($(this).find('td:first-child input[type="checkbox"]').is(':checked')) {
                    trActive = $(this);
                    index = i;
                    txt = $(this).find('td').eq(2).html();
                }
            });
            var to_division = data[index]['to_division'],
                to_career = data[index]['to_career'];
            if (trActive.hasClass('forbidden')) {
                alertMs('你没有操作' + trActive.children().eq(2).html() + '的权限');
                return false;
            } else {
                var projectName = trActive.find('td').eq(2)[0].innerHTML,
                    status = trActive.find('td').eq(1)[0].innerHTML;
                if (status.indexOf('未接收') == -1) {
                    alertMs('只能取消上报未接收的项目');
                } else {
                    alertMs('取消上报项目：' + projectName + '', 2, function () {
                        $.post('/api/enrol_project?project_id=' + trActive.attr('data-id') + '&status=' + encodeURI('未上报') + '&to_division=' + to_division + '&to_career=' + to_career + '&user_name=' + localStorage.user_name, {}, function () {
                            var dataLog = [getDate(0), localStorage.name, '取消上报了' + txt];
                            dataLog = JSON.stringify(dataLog);
                            $.post('/api/set_log?project_id=' + trActive.attr('data-id'), dataLog, function () {
                                location.reload();
                            })
                        })
                    });
                }
            }
            break;
        default:
            alertMs('只能勾选一条数据进行取消上报操作');
            return false;
            break;
    }
}

function createMap() {
    var list = '',
        xmlb = '',
        type = $('[id^=map].active', parent.document).attr('data-type');
    if ($('.xmlb-two option:selected').val() != '') {
        xmlb = $('.xmlb-two option:selected').val();
        type = $('.xmlb-one option:selected').val();
    } else {
        if ($('.xmlb-one option:selected').val() != '') {
            type = $('.xmlb-one option:selected').val();
        }
    }
    var pointArr = [];
    $.post('/api/zhfx?name=' + $('.xm-name input').val() + '&up_org=' + getxzqhCode('search-xzqh')[0] + '&xmlb=' + xmlb + '&type=' + type, {}, function (res) {
        var total = res['total'];
        list = res['project_list'];
        for (var i = 0; i < list.length; i++) {
            if (!!list[i]['content']['T_LXKZD']) {
                var kzd = list[i]['content']['T_LXKZD'];
                for (var m = 0; m < kzd.length; m++) {
                    for (var n = 0; n < kzd[m].length; n++) {
                        var jd = kzd[m][n]['JD'],
                            wd = kzd[m][n]['WD'];
                        var img = '<img class="item-img" data-id="' + list[i]['identifier'] + '" src="../image/mark.png" style="cursor:pointer;width:20px;" />';
                        var marker = new MMarker(
                            new MPoint(jd, wd),
                            new MIcon(img)
                        );
                        maplet.addOverlay(marker);
                        if (kzd[m][n]['WZBS'] != '2') {
                            pointArr.push(new MPoint(jd, wd));
                        } else {
                            pointArr.push(new MPoint(jd, wd));
                            maplet.addOverlay(new MPolyline(pointArr));
                            pointArr = [];
                        }
                    }
                }
            } else {
                var point = list[i]['content']['map_local'];
                if (point != undefined) {
                    for (var a = 0; a < point.length; a++) {
                        var img = '<img class="item-img" data-id="' + list[i]['identifier'] + '" src="../image/mark.png" style="cursor:pointer;width:20px;" />';
                        var marker = new MMarker(
                            new MPoint(point[a][0], point[a][1]),
                            new MIcon(img)
                        );
                        maplet.addOverlay(marker);
                        pointArr.push(new MPoint(point[a][0], point[a][1]));
                        if (a == point.length - 1) {
                            maplet.addOverlay(new MPolyline(pointArr));
                            pointArr = [];
                        }
                    }
                }
            }
        }
        mapTable(total);
    })
    $('body').on('click', '.item-img', function () {
        var id = $(this).attr('data-id');
        var detailHtml = '';
        for (var i = 0; i < list.length; i++) {
            if (list[i]['identifier'] == id) {
                var yearContent = list[i]['content']['GS_NDJH_NDJYJH'];
                detailHtml = '<div><span>项目名称：</span><span>' + list[i]['XMMC'] + '</span></div>' +
                    '<div><span>计划安排年份:</span><span>' + yearContent['JHNF'] + '</span></div>' +
                    '<div><span>总投资(万元):</span><span>' + yearContent['ZTZ'] + '</span></div>' +
                    '<div><span>中央投资(万元):</span><span>' + yearContent['ZYTZ'] + '</span></div>' +
                    '<div><span>建设开工年:</span><span>' + yearContent['JSKGN'] + '</span></div>' +
                    '<div><span>建设完工年:</span><span>' + yearContent['JSWGN'] + '</span></div>' +
                    '<div><span>年度建议计划投资(万元):</span><span>' + yearContent['NDJYJHZE'] + '</span></div>' +
                    '<div><span>年度建议投资中央投资(万元):</span><span>' + yearContent['NDJHZYTZ'] + '</span></div>';
            }
        }
        $('.map-detail').empty().append(detailHtml);
    });
}


function mapTable(total) {
    var tbodyHtml = '';
    for (var i = 0; i < total.length; i++) {
        $('.map-table tbody td').eq(i).html(total[i]);
    }
}

//打印表格
function printTable() {
    var tableToPrint = $('.printTable')[0];
    var iframe = document.createElement('iframe');
    iframe.src = '../iframes/iframe_print.html';
    document.body.appendChild(iframe);
    var ifrdoc = iframe.contentWindow.document;
    ifrdoc.designMode = "on"; //文档进入可编辑模式
    iframe.setAttribute('style','display:none;');
    ifrdoc.open(); //打开流
    ifrdoc.write(tableToPrint.outerHTML);
    ifrdoc.close(); //关闭流
    iframe.contentWindow.focus();
    iframe.contentWindow.print();
    ifrdoc.designMode = "off"; //文档进入非可编辑模式
    document.body.removeChild(iframe); 
}

//导出表格
function exportTable() {
    var str = "<div class='export-div'>" +
        "<label class='export-label'>请输入导出名：</label><input type='text' class='exportname' style='color: #333;'/></div>" +
        "<div class='export-div none'>" +
        "<label class='export-label'>描述：</label><input type='text' class='description' style='color: #333'/></div>" +
        "<div class='export-div none'>" +
        "<label class='export-label'>数据上报下达类型：</label>" +
        "<select class='uploadflag export-select'><option value=''>--请选择--</option><option value='0'>省级上报</option><option value='1'>部级下达</option></select></div>" +
        "<div class='export-div none'>" +
        "<label class='export-label'>数据类型：</label>" +
        "<select class='taskcode export-select'><option value=''>--请选择--</option><option value='0'>计划数据</option><option value='1'>备案数据</option></select></div>" +
        "<div class='export-div none'>" +
        "<label class='export-label'>计划编制年度：</label><input type='number' class='jhbznd' style='color:#333;'/></div>" +
        "<div class='export-div none'>" +
        "<label class='export-label'>批次：</label>" +
        "<select class='pc export-select'><option value=''>--请选择--</option><option value='1'>第一批</option><option value='2'>第二批</option><option value='3'>第三批</option></select></div>" +
        "<div class='export-div'>" +
        "<span class='xml way export-type none' data-export='xml'><input type='radio' name='type'/>XML</span>" +
        "<span class='excel way export-type' data-export='excel'><input type='radio' name='type'/>excel</span>" +
        "<span class='csv way export-type' data-export='csv'><input type='radio' name='type'/>csv</span>" +
        "<span class='pdf way export-type' data-export='pdf'><input type='radio' name='type'/>pdf</span>" +
        "</div>";
    var larr = top.location.pathname.split('.')[0].split('/'),
        type = larr[larr.length - 1];
    alertMs(str, 2, function () {
        if ($('.way.active').attr('data-export') == "excel" || $('.way.active').attr('data-export') == "csv") {
            if ($('.printAA').length > 0) {
                $('.printAA').show();
            } else {
                var printClone = $('.printTable').parent().clone().css('overflow', 'visible').addClass('printAA');
                $('body').append(printClone);
                $('body').find('.printAA tbody>tr').removeClass('none');
            }
            $('body').find('.printAA.tabstyle td,.printAA.tabstyle th').css('white-space', 'nowrap');
            $('body').find('.printAA .table-container td,.printAA .table-container th').css('padding', '.5em 1em');
            $('.printAA .data-table').tableExport({
                fileName: sFileName,
                type: $('.way.active').attr('data-export')
            });
            $('.printAA').hide();
        } else if ($('.way.active').attr('data-export') == "pdf") {
            if ($('.printAA').length > 0) {
                $('.printAA').show();
            } else {
                var printClone = $('.printTable').parent().clone().css('overflow', 'visible').addClass('printAA');
                $('body').append(printClone);
                $('body').find('.printAA tbody>tr').removeClass('none');
            }
            if ($('.printAA table').width() > 2060) {
                $('body').find('.printAA.tabstyle td,.printAA.tabstyle th').css('white-space', 'normal');
                $('body').find('.printAA .table-container td,.printAA .table-container th').css('padding', '5px 7px');
            }
            $('.printAA .data-table').tableExport({
                fileName: sFileName,
                type: 'pdf',
                jspdf: {
                    orientation: 'p',
                    margins: {
                        left: 20,
                        top: 10
                    },
                    autotable: false
                }
            });
            $('.printAA').hide();
        } else {
            var bb = '';
            if (/^(nc)/.test(type)) {
                //农村
                var description = $('.description').val(),
                    uploadflag = $('.uploadflag').val(),
                    taskcode = $('.taskcode option:selected').val(),
                    jhbznd = $('.jhbznd').val(),
                    pc = $('.pc option:selected').val();
                bbb = '<a href="/api/' + sFileName + '.' + $('.way.active').attr('data-export') + '?file_id=export_ncgl&project_type=&status=审核通过审批未接收&description=' + description + '&tbdwdm=331000000&tbdwmc=浙江省交通运输厅&uploadflag=' + uploadflag + '&taskcode=' + taskcode + '&jhbznd=' + jhbznd + '&pc=' + pc + '" style="opacity: 0""><div class="bbb"></div></a>';
            } else if (type == 'gljy' || type == 'syjy' || type == 'zcxt') {
                // 部
                jhbznd = $('.jhbznd').val(),
                    pc = $('.pc option:selected').val();
                bbb = '<a href="/api/' + sFileName + '.' + $('.way.active').attr('data-export') + '?file_id=export&project_type=' + type + '&status=审核通过审批未接收&jhbznd=' + jhbznd + '&pc=' + pc + '" style="opacity: 0"><div class="bbb"></div></a>';
            } else if (type == 'lnxm') {
                bbb = '<a href="/api/' + sFileName + '.' + $('.way.active').attr('data-export') + '?file_id=export_history&project_type=' + $('[id^=lnxm].active', parent.document).attr('data-type') + '" style="opacity: 0"><div class="bbb"></div></a>';
            }
            $('body').append($(bbb));
            $('.bbb').trigger('click');
            $(bbb).remove();
        }
    });

    if (type == 'gljy' || type == 'syjy' || type == 'zcxt' || /^(nc)/.test(type) || type == 'lnxm') $('.xml').show();
    var sFileName = '';
    $('.way').on('click', function () {
        $(this).addClass('active').css('color', '#ffc1be').siblings().removeClass('active').css('color', '#fff');
        $('.export-div').eq(1).addClass('none');
        $('.export-div').eq(2).addClass('none');
        $('.export-div').eq(3).addClass('none');
        $('.export-div').eq(4).addClass('none');
        $('.export-div').eq(5).addClass('none');
    })
    $('.exportname').on('change', function () {
        sFileName = $(this).val();
    })
    $('.excel').click(function () {
        $(this).addClass('active')
    })
    $('.csv').click(function () {
        $(this).addClass('active')
    })
    $('.pdf').click(function () {
        $(this).addClass('active')
    })
    $('.xml').click(function () {
        $(this).addClass('active');
        var larr = top.location.pathname.split('.')[0].split('/');
        type = larr[larr.length - 1];
        if (/^(nc)/.test(type)) {
            $('.export-div').eq(1).removeClass('none');
            $('.export-div').eq(2).removeClass('none');
            $('.export-div').eq(3).removeClass('none');
            $('.export-div').eq(4).removeClass('none');
            $('.export-div').eq(5).removeClass('none');
        } else if (type == 'gljy' || type == 'syjy' || type == 'zcxt') {
            $('.export-div').eq(4).removeClass('none');
            $('.export-div').eq(5).removeClass('none');
        }
    });
}

/**
 * @name:DOM, the maplet init dom 
 * @file:string, the file name you'll save
 * @crossIp:string, the http proxy to get cross-domain image
**/
function toImg(name, file, crossIp) {
    var imgs = $('#' + name + ' img');
    imgs.each(function (key, item) {
        $(this).attr('crossOrigin', 'anonymous');
        var src = $(this).attr('src');
        if (src.indexOf('maplite') != '-1' || src.indexOf('GetPng') != '-1') {
            $(this).attr('src', src.replace(/(.*)(\/maplite|\/GetPng)(.*)/gi, '$2$3?' + Date.parse(new Date())));
        }
    });

    var nodesToRecover = [];
    var nodesToRemove = [];
    var $targetElem = $('#' + name);
    var $svgElem = $targetElem.find('svg');
    $svgElem.each(function (index, node) {
        var parentNode = node.parentNode;
        var svg = $('<div>').append($(this).clone()).html().replace(/(<marker[\s\S]*<\/marker>)/g, '');
        var canvas = document.createElement('canvas');

        canvas.style.position = 'absolute';
        canvas.style.left = '-900px';
        canvas.style.top = '-400px';

        canvg(canvas, svg, { ignoreMouse: true, ignoreAnimation: true });

        //将svg转换成canvas
        nodesToRecover.push({
            parent: parentNode,
            child: node
        });
        parentNode.removeChild(node);

        nodesToRemove.push({
            parent: parentNode,
            child: canvas
        });

        parentNode.appendChild(canvas);

    });

    html2canvas($targetElem, {
        useCORS: true,
        allowTaint: true,
        onrendered: function (canvas) {
            var a = document.createElement('a');
            a.href = canvas.toDataURL('image/jpeg');
            a.download = file + '.jpg';
            a.click();
            //恢复svg
            nodesToRemove.forEach(function (pair) {
                pair.parent.removeChild(pair.child);
            });

            nodesToRecover.forEach(function (pair) {
                pair.parent.appendChild(pair.child);
            });
        },
        width: $targetElem.width(),
        height: $targetElem.height()
    });
}

//随机id标记
function guid() {
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}

//项目赋码
function getCoding(result) {
    if (result['content'] == undefined) {
        $('.xmfm-container').slideDown();
        var project = result[0]['project'],
            approval = result[0]['approval'];
        $('.fm-basic p').html('项目信息');
        var fmContent = '<div class="col-sm-3"><span>行政区划代码：</span><span>' + project['area'] + '</span></div>' +
            '<div class="col-sm-3"><span>行政区划描述：</span><span>' + project['area_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目法人证照号码：</span><span>' + project['cert_num'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目法人证照类型代码：</span><span>' + project['cert_type'] + '</span></div>' +
            '<div class="col-sm-6"><span>项目法人证照类型描述：</span><span>' + project['cert_type_desc'] + '</span></div>' +
            '<div class="col-sm-6"><span>项目赋码：</span><span>' + project['code'] + '</span></div>' +
            '<div class="col-sm-3"><span>联系人邮箱：</span><span>' + project['contact_email'] + '</span></div>' +
            '<div class="col-sm-3"><span>联系人姓名：</span><span>' + project['contact_name'] + '</span></div>' +
            '<div class="col-sm-3"><span>联系人QQ：</span><span>' + project['contact_qq'] + '</span></div>' +
            '<div class="col-sm-3"><span>联系人电话：</span><span>' + project['contact_tel'] + '</span></div>' +
            '<div class="col-sm-3"><span>联系人微信：</span><span>' + project['contact_wechat'] + '</span></div>' +
            '<div class="col-sm-3"><span>拟建成时间(年)：</span><span>' + project['end_year'] + '</span></div>' +
            '<div class="col-sm-6"><span>项目法人单位：</span><span>' + project['enterprise'] + '</span></div>' +
            '<div class="col-sm-6"><span>项目ID：</span><span>' + project['id'] + '</span></div>' +
            '<div class="col-sm-3"><span>国标行业代码：</span><span>' + project['industry'] + '</span></div>' +
            '<div class="col-sm-3"><span>国标行业描述：</span><span>' + project['industry_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>是否是开发区项目：</span><span>' + project['is_development_area'] + '</span></div>' +
            '<div class="col-sm-3"><span>建设地点代码：</span><span>' + project['location'] + '</span></div>' +
            '<div class="col-sm-3"><span>建设地点描述：</span><span>' + project['location_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>建设地点详情：</span><span>' + project['location_detail'] + '</span></div>' +
            '<div class="col-sm-6"><span>项目名称：</span><span>' + project['name'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目性质代码：</span><span>' + project['nature'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目性质描述：</span><span>' + project['nature_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>投资项目核准目录编码：</span><span>' + project['permit_code'] + '</span></div>' +
            // '<div class="col-sm-3"><span>投资项目行业分类代码：</span><span>' + project['permit_industry'] + '</span></div>' +
            '<div class="col-sm-3"><span>投资项目行业分类描述：</span><span>' + project['permit_industry_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人职务：</span><span>' + project['permit_post'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人邮箱：</span><span>' + project['principal_email'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人姓名：</span><span>' + project['principal_name'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人QQ：</span><span>' + project['principal_qq'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人电话：</span><span>' + project['principal_tel'] + '</span></div>' +
            '<div class="col-sm-3"><span>负责人微信：</span><span>' + project['principal_wechat'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目阶段：</span><span>' + project['stage'] + '</span></div>' +
            '<div class="col-sm-3"><span>拟开工时间(年)：</span><span>' + project['start_year'] + '</span></div>' +
            '<div class="col-sm-3"><span>总投资(万元)：</span><span>' + project['total'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目类型代码：</span><span>' + project['type'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目类型描述：</span><span>' + project['type_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>所属行业代码：</span><span>' + project['the_industry'] + '</span></div>' +
            '<div class="col-sm-3"><span>所属行业代码描述：</span><span>' + project['the_industry_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>项目属性：</span><span>' + (project['project_attribute'] == '0' ? '基础建设' : '技术改造') + '</span></div>' +
            '<div class="col-sm-3"><span>所属代码描述：</span><span>' + project['project_attribute_desc'] + '</span></div>' +
            '<div class="col-sm-3"><span>时间戳：</span><span>' + project['update_time'] + '</span></div>' +
            '<div class="col-sm-12"><span>建设规模及内容：</span><span>' + project['content'] + '</span></div>';
        $('.fm-basic-content').empty().append(fmContent);
        if (approval != undefined) {
            $('.fm-approve p').html('项目事项办理信息');
            var pHtml = '',
                pBody = '',
                pAll = '';
            approval.map(function (value, i) {
                pHtml = '';
                pBody = '';
                pHtml += '<div class="col-sm-12"><p>批复信息' + parseInt(i + 1) + '：</p></div>';
                pBody += '<div class="col-sm-3"><span>项目所在行政区划代码:</span><span>' + value['area'] + '</span></div>' +
                    '<div class="col-sm-3"><span>项目所在行政区划描述:</span><span>' + value['area_desc'] + '</span></div>' +
                    '<div class="col-sm-6"><span>项目代码:</span><span>' + value['code'] + '</span></div>' +
                    '<div class="col-sm-6"><span>事项申报号:</span><span>' + value['approval_item_id'] + '</span></div>' +
                    '<div class="col-sm-6"><span>事项id:</span><span>' + value['item_id'] + '</span></div>' +
                    '<div class="col-sm-6"><span>事项名称:</span><span>' + value['item_name'] + '</span></div>' +
                    '<div class="col-sm-3"><span>事项办理状态:</span><span>' + value['current_state'] + '</span></div>' +
                    '<div class="col-sm-3"><span>事项办理状态描述:</span><span>' + value['current_state_desc'] + '</span></div>' +
                    '<div class="col-sm-3"><span>批复文号:</span><span>' + value['approval_numble'] + '</span></div>' +
                    '<div class="col-sm-6"><span>批复文件标题:</span><span>' + value['approval_title'] + '</span></div>' +
                    '<div class="col-sm-3"><span>办理时间:</span><span>' + value['deal_time'] + '</span></div>' +
                    '<div class="col-sm-3"><span>办理部门编码:</span><span>' + value['dept_code'] + '</span></div>' +
                    '<div class="col-sm-3"><span>办理部门名称:</span><span>' + value['dept_name'] + '</span></div>' +
                    '<div class="col-sm-3"><span>时间戳:</span><span>' + value['update_time'] + '</span></div>';
                pAll += pHtml + pBody;
            });
            $('.fm-approve-content').empty().append(pAll);
        }
    } else {
        $('.xmfm-container').show();
        $('.fm-basic p').html(result['content']);
        $('.fm-basic-content').empty();
        $('.fm-approve-content').empty();
    }
    $('.xmfm-search span').eq(1).on('click', function () {
        $('.xmfm-container').slideUp();
    });
    $('.xmfm-search span').eq(0).on('click', function () {
        $('.xmfm-container').slideDown();
    });
}
